CoCreate User Forum  

Go Back   CoCreate User Forum > Support > Customization

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 11-19-2013, 10:30 AM
tom kirkman's Avatar
tom kirkman tom kirkman is offline
Registered User
 
Join Date: Oct 2002
Location: Perrysburg, Ohio
Posts: 397
remove workplanes from drawlist

I am trying to write a lisp program that will go through the existing drawlist and remove workplanes from that drawlist. This is what I currently have. I know it is not right, but it is an attempt. If anybody can provide pointers as to the correct commands, I would appreciate it.

Thanks

Tom
Code:
(in-package :custom)
(use-package :OLI)

;;--------------------------------------------------------------------------*

(sd-defdialog 'remove_workplanes
:dialog-title "Remove Workplanes"
:toolbox-button T
;;:dialog-control :sequential
:variables
  '(
   )
:local-functions
  '(
    (wpremove-action ()
     (let (viewportlist worklist)
	    (setf viewportlist (sd-inq-vp-drawlist-objects (oli::sd-inq-current-vp)))
      (dolist (worklist viewportlist)
	  (if (sd-inq-workplane-p worklist)(remove_from_vp_drawlist worklist))
      );;dolist
     );;let
    )
			)
:ok-action
   '(sd-call-cmds (wpremove-action))
:help-action '()
)
__________________
Tom Kirkman

Creo Elements/Direct 20.1
Dell Precision 3581
https://www.o-i.com
Reply With Quote
  #2  
Old 11-20-2013, 06:35 AM
Andy Poulsen Andy Poulsen is offline
Administrator
 
Join Date: Apr 2003
Location: Fort Collins, Colorado
Posts: 273
Re: remove workplanes from drawlist

Hi Tom,

You're on the right track -- you were only missing one parameter (the viewport) on the function to remove the object from the drawlist.

You can do it with an even simpler method, though. There's no need to include empty sections, and you can also avoid some of the intermediate variables and function definitions.

In this case, I just decided to use a variable with an :initial-value statement to run the code -- no separate function calls or function definition required! As soon as you press the toolbox button, the workplanes will be removed (no dialog on screen). If you prefer the dialog to be displayed and then press a button to remove the workplanes, just change :initial-value to :push-action.

Here's what I came up with:
Code:
(in-package :custom)
(use-package :oli)

(sd-defdialog 'remove_workplanes
  :dialog-title "Remove Workplanes"
  :toolbox-button t
  :variables
  '((remove-wps :initial-value  ;; this will be executed when the dialog starts
		(let ((vp (sd-inq-current-vp)))
		  (dolist (obj (sd-inq-vp-drawlist-objects vp))
		    (when (sd-inq-workplane-p obj)
		      (remove_from_vp_drawlist vp obj)))
		  ;; after processing all items, cancel this dialog
		  (sd-put-buffer "cancel"))))
  )
I hope this helps. If you have any questions, just ask! :)

andy
__________________
Andy Poulsen
AI MAXTools: Dream. Design. Done. It's that easy!
Add-ins bringing new functionality and speed to Creo Elements/Direct and CoCreate products. Now available for v17-v20+!
See them in action at www.ai-maxtools.com and then try them for yourself -- FREE!
Reply With Quote
  #3  
Old 11-20-2013, 07:00 AM
tom kirkman's Avatar
tom kirkman tom kirkman is offline
Registered User
 
Join Date: Oct 2002
Location: Perrysburg, Ohio
Posts: 397
Re: remove workplanes from drawlist

Andy

Thank you. This definitley simplifies what I was trying to do.

Tom
__________________
Tom Kirkman

Creo Elements/Direct 20.1
Dell Precision 3581
https://www.o-i.com
Reply With Quote
  #4  
Old 11-20-2013, 07:19 AM
tom kirkman's Avatar
tom kirkman tom kirkman is offline
Registered User
 
Join Date: Oct 2002
Location: Perrysburg, Ohio
Posts: 397
Re: remove workplanes from drawlist

Andy

This works well unless the workplane is buried deep in sub assemblies. I added the line (display obj) just to see what is being processed. It seems only look into objects in the root or top level assembly.

Any ideas?

The assembly I have has 112,414 parts, in 10135 assemblies.

Tom
__________________
Tom Kirkman

Creo Elements/Direct 20.1
Dell Precision 3581
https://www.o-i.com
Reply With Quote
  #5  
Old 11-20-2013, 10:57 AM
Andy Poulsen Andy Poulsen is offline
Administrator
 
Join Date: Apr 2003
Location: Fort Collins, Colorado
Posts: 273
Re: remove workplanes from drawlist

Quote:
Originally Posted by tom kirkman View Post
Andy

This works well unless the workplane is buried deep in sub assemblies. I added the line (display obj) just to see what is being processed. It seems only look into objects in the root or top level assembly.

Any ideas?

The assembly I have has 112,414 parts, in 10135 assemblies.

Tom
Hi Tom,

Yeah, that actually makes sense -- querying the drawlist only gives you the highest-level object that can completely identify what's displayed. If you have a single assembly loaded with 100,000 objects in it, and that entire assembly is turned on, querying the drawlist will only show a single object (the top-level assembly).

So, rather than trying to figure out which workplanes are shown, we can just query all objects in the system, and turn off only the workplanes. There are inefficiencies both ways, but this may be the quickest and cleanest. Here's the next pass:
Code:
(in-package :custom)
(use-package :oli)

;; Define a function to return a list of all child objects of a given object
;;  Then call it recursively to get a list of all objects under the initial
;;  top-level object.
(defun inq-obj-tree-list (obj)
  (cons 
   obj
   (apply #'nconc (mapcar #'inq-obj-tree-list (sd-inq-obj-children obj)))))

(sd-defdialog 'remove_workplanes
  :dialog-title "Remove Workplanes"
  :toolbox-button t
  :variables
  '((remove-em :initial-value
	       (let ((vp (sd-inq-current-vp)))
		 (dolist (obj (inq-obj-tree-list (sd-pathname-to-obj "/")))
		   (when (sd-inq-workplane-p obj)
		     (remove_from_vp_drawlist vp obj)))
		 (sd-put-buffer "cancel"))))
  )
That seems to work here...

Does that do the trick for you? How long does it take to process all objects? I think it should be fairly quick, but I don't have any assemblies that size...
__________________
Andy Poulsen
AI MAXTools: Dream. Design. Done. It's that easy!
Add-ins bringing new functionality and speed to Creo Elements/Direct and CoCreate products. Now available for v17-v20+!
See them in action at www.ai-maxtools.com and then try them for yourself -- FREE!
Reply With Quote
  #6  
Old 11-20-2013, 11:30 AM
tom kirkman's Avatar
tom kirkman tom kirkman is offline
Registered User
 
Join Date: Oct 2002
Location: Perrysburg, Ohio
Posts: 397
Re: remove workplanes from drawlist

Code:
(defun inq-obj-tree-list (obj)
  (cons 
   obj
   (apply #'nconc (mapcar #'inq-obj-tree-list (sd-inq-obj-children obj)))))
If I follow this correctly (I have not worked with cons, apply or nconc before. This code constucts a list (cons) by adding the top level object to the list, then the children of the object and then the children of the children, etc.?

This code worked, it took 7 seconds from start to finish. This is a big improvement over the hunt method used before.

Thanks for your help with this

Tom
__________________
Tom Kirkman

Creo Elements/Direct 20.1
Dell Precision 3581
https://www.o-i.com
Reply With Quote
  #7  
Old 11-20-2013, 09:14 PM
Andy Poulsen Andy Poulsen is offline
Administrator
 
Join Date: Apr 2003
Location: Fort Collins, Colorado
Posts: 273
Re: remove workplanes from drawlist

Quote:
Originally Posted by tom kirkman View Post
Code:
(defun inq-obj-tree-list (obj)
  (cons 
   obj
   (apply #'nconc (mapcar #'inq-obj-tree-list (sd-inq-obj-children obj)))))
If I follow this correctly (I have not worked with cons, apply or nconc before. This code constucts a list (cons) by adding the top level object to the list, then the children of the object and then the children of the children, etc.?
That's correct -- nconc basically adds the stuff on to the existing list that it's building, and it cascades down the tree. Pretty slick, actually -- I've been using variations of that function since I first saw it back in 1995 from one of the developers of what was then called SolidDesigner.

Quote:
Originally Posted by tom kirkman View Post
This code worked, it took 7 seconds from start to finish. This is a big improvement over the hunt method used before.

Thanks for your help with this

Tom
Excellent -- glad to help! That's great that it's working well for you!

andy
__________________
Andy Poulsen
AI MAXTools: Dream. Design. Done. It's that easy!
Add-ins bringing new functionality and speed to Creo Elements/Direct and CoCreate products. Now available for v17-v20+!
See them in action at www.ai-maxtools.com and then try them for yourself -- FREE!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 05:36 PM.



Hosted by SureServer    Forums   Modeling FAQ   Macro Site   Vendor/Contractors   Software Resellers   CoCreate   Gallery   Home   Board Members   Regional User Groups  By-Laws  

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.