Jump to content

Recommended Posts

Posted

I studied Lee Macs fantastic posting at:

 

http://www.cadtutor.net/forum/showthread.php?53374-xref-clip-boundry&p=361940&viewfull=1#post361940

 

and learned so much in a very short time. This explains things and puts many more of the pieces of the puzzle together for me. I am really starting to understand the Object Model and how to access items therein. Or at least I thought so.

 

In testing some code I'm working on which turns on a bunch of layers, I find myself having to manually go back and turn the layers back off in order to test again. So I thought why not write a vlisp snippet which would take a list of the layers I just turned on and turn them back off. Here is what I came up with but of course this is not working just yet.

 


(defun C:LayerOff (/ acadDocument theLayers thelist)
 (setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
 (setq theLayers (vla-get-layers acadDocument))
 (setq theList '("Layer 1"
                     "Layer 2"
                     "Layer 3"
                     "Layer 4"
                     "Layer 5"
                     "Layer 6"
                     "Layer 7l")
 )     
 (vlax-for item thelist (vlax-put-property item "LayerOn" ':vlax-false) ) 
 (princ) 
);defun 
(princ)

I got this from a code which turns on all the layers using the vaiable theLayers. I had hoped to modify it to just turn off the layers in thelist. Can someone point me in the right direction with this.

Posted

Some hints...

 

vlax-for operates on Visual LISP Collection objects, not lists, the list equivalent is foreach.

 

Also, the LayerOn property is a property of the VLA Layer Object, you are attempting to change the property of a string.

Posted

check this out ....

 

 

(vlax-for item thelist (vlax-put-property (vla-item thelayers item) "LayerOn" ':vlax-false) ) 

Posted
check this out ....

 

 

(vlax-for item thelist (vlax-put-property (vla-item thelayers item) "LayerOn" ':vlax-false) ) 

*cough*vl-catch-all-apply check if layer actually exists*cough*

Posted (edited)

Been distracted for the last hour and just getting back to this. I tried this and it did not work. Ended up with:

 

; error: bad argument type: VLA-object collection:

 

I think Lee Mac made the point that vlax-for only works on Collection Objects, not a list which 'thelist' is. I will hack at this some more tonight.

Edited by Bill Tillman
Posted
check this out ....

 

 

(vlax-for item thelist (vlax-put-property (vla-item thelayers item) "LayerOn" ':vlax-false) ) 

 

*cough* 'thelist' is not a collection *cough*

Posted

OK I got this working but using a command process instead:

 

(defun C:LayerOff ()
 (foreach a '("Layer 1"
           "Layer 2"
          "Layer 3"
          "Layer 4"
          "Layer 5"
          "Layer 6"
          "Layer 7")
   (command "._layer" "off" a "")
  )
)

But this does not use Active X which was my intentions here. Will keep hacking on this one later.

Posted

You might find it easier approaching it in the opposite direction, here's a start:

 

(setq mylst
  '(
       "Layer1"
       "Layer2"
       "Layer3"
       "Layer4"
       "Layer5"
       "Layer6"
       "Layer7"
   )
)
(vlax-for LayerObj (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
   (if ...
)

 

I'll challenge you to finish it :twisted:

Posted

Lee,

 

Your ingenious in these matters always amazes me. I spent most of my free time last night watching the new Visual Basic 2010 Express videos learning about classes, objects and methods. We are going to make the switch here soon as AutoDesk looks like they are pulling out of the VBA camp, as are many other app vendors. However, I will try to finish the above code. I'm curious about one thing though. Beside the Active X model and so forth, what makes this:

 

(setq acadobject (vlax-get-Acad-Object))
(setq activedocument (vla-get-activedocument acadobject))
(setq LayerTable (vla-get-layers activedocument))

(vla-put-layeron (vlax-invoke-method LayerTable "Item" "My_layer") :vlax-false)

any better than this:

 

 (command "._layer" "off" "My_Layer" "")

Posted
Beside the Active X model and so forth, what makes this:

 

(setq acadobject (vlax-get-Acad-Object))
(setq activedocument (vla-get-activedocument acadobject))
(setq LayerTable (vla-get-layers activedocument))

(vla-put-layeron (vlax-invoke-method LayerTable "Item" "My_layer") :vlax-false)

any better than this:

 

 (command "._layer" "off" "My_Layer" "")

 

ActiveX method:

 

  • Faster
  • Works with ObjectDBX
  • More error trapping permitted

Command method:

 

  • More concise
  • Easier for n00bs

Posted

Put the first two lines either in a defun and autoload or just autoload, this way you have the "activedocument" open for any of your programs, I know only saves two lines of code. eg (active) then why not (layertabs) = (setq LayerTable (vla-get-layers activedocument)) maybe write a few library defuns for the most common used stuff. layer on/off ?

 

Also like the other comment in another post I am sure by Lee the old fashioned lisp writer's like me compares .net VL etc to about 5 times the lines of code required with new Pc's is speed really a problem ? I am though using VL more its makes property request easier to read rather than DXF codes.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...