Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

assoc 2 = anonymous name not block name

17 REPLIES 17
Reply
Message 1 of 18
PeterLange7168
785 Views, 17 Replies

assoc 2 = anonymous name not block name

I am trying to create a selection set by selecting each occurance of certain blocks. I have a routing written:

(ssget "X" '((-4 . " (2 . "os-cedt")
(2 . "os-codt")
(2 . "os-cous")
(2 . "os-coir")
(2 . "os-wst")
(-4 . "OR>")))

I was getting the proper results, then I was only getting 1 or none in my selection set. I finally determined that the assoc 2 is returning the Anonymous Name of the block (impossible to predict) instead of my defined block name. I am not really sure how to guarantee 100% selecting all of these named blocks if assoc 2 will not consistently be Block Name. I am just looking for some ideas. Thanks in advance.
17 REPLIES 17
Message 2 of 18
balisteor
in reply to: PeterLange7168

the problem may be that they are dynamic blocks

these will return the right block name every time, but wont work within ssget.
(vla-get-effectivename (vlax-ename->vla-object (car (entsel ))))
or
(vla-get-effectivename (vlax-ename->vla-object entity )



Hopefully that helps you.
:D
Message 3 of 18

They are Dynamic Blocks. I was just hoping to create a selection set so that my users could select all these blocks quickly without using Filter. These blocks were chosen specifically because of common visibility settings. Your solution produces the correct result, I just don't know if that is going to be practical to use to search entire drawing.
Message 4 of 18
Anonymous
in reply to: PeterLange7168

There have been many previous discussions on obtaining
a selection set of dynamic blocks within this group. You
should try a search and see what comes up then post back
if you are still having issues.


wrote in message news:6296802@discussion.autodesk.com...
They are Dynamic Blocks. I was just hoping to create a selection set so that my users could select all these blocks quickly without
using Filter. These blocks were chosen specifically because of common visibility settings. Your solution produces the correct
result, I just don't know if that is going to be practical to use to search entire drawing.
Message 5 of 18
cab2k
in reply to: PeterLange7168

This may help you in the future:
(ssget "X" '((2 . "os-cedt,os-codt,os-cous,os-coir,os-wst")))
Message 6 of 18
balisteor
in reply to: PeterLange7168

Hey, Peter.

As Jason Piercey mentioned this has been done before but I thought Id throw something together anyways.


{code}
(defun selsetofdynamicblocks ( selset / blocklist ss_count object entity blockname ssout )
(setq ss_count 0 blocklist '("os-cedt" "os-codt" "os-cous" "os-coir" "os-wst"))
( while ( setq entity ( ssname selset ss_count ))
(setq object (vlax-ename->vla-object entity ))

(if (vlax-property-available-p object 'effectivename)
(progn
(setq blockname (vla-get-effectivename object ))
(if
(member (strcase blockname T ) blocklist )
(progn
(if ssout (setq ssout (ssadd entity ssout)) (setq ssout (ssadd entity )) );i
);p
);i
);p
);i

(setq ss_count ( + 1 ss_count ))
);w
ssout
);d

{code}

You can then use:
(selsetofdynamicblocks (ssget "X"))
And that should return exactly what you want. Edited by: balisteor on Dec 3, 2009 6:07 PM
Message 7 of 18

I do apologize for not being up to speed on dynamic blocks. We didn't upgrade from 2005 until 2008 and I missed the first few years of it. balisteor's post has helped me write a routine selecting the DB's, but in my reading it appears you can modify parameters through lisp. I am having a hard time understanding people's routines because of confusing varialbes with the "vlax" commands that I am unfamiliar with. Specifically, I want to change the visibility parameter to "ALWAYS ON". (Named identically in each DB). Or would the parameter be expressed as an integer?
Anyway, is there a reference listing what "vlax" commands are available and what they do, or could someone just post how to identify the visibility property and how it is modified. I can play around with other parameters as needed.

Again, thanks so much for the help so far.

My version follows with ssout being the selection set of the desired dynamic blocks.

(defun selsetofdynamicblocks ( selset / 0lay blocklist ss_count object entity blockname ssout )
(setq PERROR *error*)
(setq *error* ETRAP)
(setq CLFN "OCCUPANCY SENS VIS ON")
(setq selset (ssget "X" '((0 . "INSERT"))))
(setq ss_count 0 blocklist '("os-cedt" "os-codt" "os-cous" "os-coir" "os-wst"))
(while (setq entity (ssname selset ss_count))
(setq object (vlax-ename->vla-object entity))
(if (vlax-property-available-p object 'effectivename)
(progn
(setq blockname (vla-get-effectivename object ))
(if (member (strcase blockname T) blocklist)
(progn
(if ssout (setq ssout (ssadd entity ssout)) (setq ssout (ssadd entity)));i
);p
);i
);p
);i
(setq ss_count (1+ ss_count))
);w
ssout
(setq *error* PERROR)
(setvar "cmdecho" 1)
(princ)
)
Message 8 of 18
balisteor
in reply to: PeterLange7168

Peter,
No need to apologize this stuff isn't easy for everyone, including me. what I gave you was something that I only learned how to do in the past few months, I also have trouble with these vla and vlax functions they are somewhat similar to object oriented programming and you have to understand it in a way in order to use it. a little while back i had some time to make some programs to work with these types of functions and with help from others on this forum I see how they are used and play with them probably like you. I can't explain everything you need help with and there aren't a lot of simple references for them. I've seen many ways to use them.

An easy idea is to set the "object" to a variable like setting an "entity"
and you can get the entity name and set it to an object reference.
(setq object (vlax-ename->vla-object entity ))
then using:
(vlax-dump-object object T )
you can see all the properties and methods available to use.
you can then use (vlax-get) and (vlax-put) to change or retrive them.
of course you have (vlax-get-property) and (vlax-put-property) which are pretty much the same. And this is great because it helps to add confusion! I just use one that works for me.

for things like 'Visible property you use something like this:
{code}
;turn visible off
(if (vlax-property-available-p object 'Visible)(vlax-put-property object 'Visible -1))
;turn visible on
(if (vlax-property-available-p object 'Visible)(vlax-put-property object 'Visible 0 ))
{code}
If you try putting a property that is not available you get an error that stops all programming.

hopefully some of that helps you and makes it simple. slowly you'll figure it out.
if you want you can also email me and i can send you some free functions that Ive made that you can play with and see if they help you. with vla functions.


best regards
"Balisteor"
"balisteor@yahoo.com"
Message 9 of 18

Wow. That is so wicked cool. But, I guess my original question is, if I have a Visibilty State named "Cover ON", can I use a 'vlax-put' to automatedly change all blocks in my selection set to "Cover ON" no matter what the current state is? I ran the 'vlax-dump' on a block that was "Cover ON" and one that was "Cover OFF" and the 'Visible' variable was -1 on each, so I am not sure how to interpret that.
My AutoLISP book is 11 years old - it was about six years old when I took the Lisp class. I just don't know where a good reference is for these vlax commands (I assume they are visual lisp?).
Message 10 of 18
M_Hensley
in reply to: PeterLange7168

For a reference of available vlax commands hit F1 for help. On Contents tab pick AutoLISP, Visual LISP, and DXF. Next pick the AutoLISP Reference link and the AutoLISP help will come up. On the contents tab expand AutoLISP Reference, then AutoLISP functions then V Functions.
Message 11 of 18

I did not know they were here the whole time. I have always wished for a list like this. Thank you.
Message 12 of 18
balisteor
in reply to: PeterLange7168

Hello again Peter,
I was confused by your question. But now i know what your talking about.

Don't get the Visible property (which exists on all objects) confused with "Visibility state" on dynamic blocks they are completely different. The Visibility property that you are seeing is for the entire block (-1 being visible). As far as i know there is no option to control the "Visibility states" on dynamic blocks with a program but rather only by a user.



I could be wrong about this so you may want to start another post and ask such a question if you don't get an answer here. I will look a little more into it because id like to know.

Maybe the visibility states are stored somewhere other than in the block?
Message 13 of 18
M_Hensley
in reply to: PeterLange7168

Here is a sample lisp that changes the visibility state to "left" of the dynamic block named "Balloon 1-2". It may help you, or maybe not. Anyway here is the code and the dynamic block is attached for reference.

{code}
; alteration code, to change visibility of block
(defun c:sdb (/ esb v vval sal salnth count)
(vl-load-com)
(setq esb nil)
(while (= esb nil)
(setq esb (entsel))
(if (/= (vlax-get-property (vlax-ename->vla-object (car esb)) "effectivename") "Balloon 1-2")
(setq esb nil)
)
)
(setq obj (vlax-ename->vla-object (car esb)))
(setq v (vla-getdynamicblockproperties obj))
(setq vval (vlax-variant-value v))
(setq sal (vlax-safearray->list vval))
(setq salnth (length sal))
(setq count 0)
(while (< count salnth)
(if (= (vlax-get-property (nth count sal) "PropertyName") "Visibility")
(progn
(vlax-put-property (nth count sal) "Value" "Left")(princ)
(setq count salnth)
)
(setq count (+ count 1))
)
)
(princ)
)
{code}
Message 14 of 18
balisteor
in reply to: PeterLange7168

I'm sure M_hensley meant to reply to you but it looks as if he has solved your issue. using (vla-getdynamicblockproperties) which isn't in autocads standard help. Like i mentioned I did not know this was possible, I have tried his example and it works very nicely. I will use this in the future its quite a useful tool.

Try it out.
Message 15 of 18

Thank you all for the hard work you have put into this thread. However, I still seem to encounter problems I do not have a grasp on. I can run your routine in a drawing and it does exactly what I want - it will change the Visibility State to another predefined named state. But if I change two varialbes, "Balloon 1-2" to "os-cedt" and "Left" to "Cover OFF", it will not work on my block. I keep thinking it must be something simple that I am overlooking, but I have only changed the block name and Visibility State name to match mine. I have checked spelling, etc.

I guess I just don't understand why AutoDESK wouldn't make these changes accessible from the command line. I know dialog boxes are easy to work with, but aren't there a lot of cad mngrs who know a little lisp who would like to automate these for their users.
Message 16 of 18

My bad. My parameter is named Visibility1 not Visibility. It works very well.
Message 17 of 18

I case anyone wants to see the finished product, I amposting it. I am very happy with how it works, it searches entire drawing for specific dynamic blocks and will change them with one mouse click. No missed selecting blocks, no changing parameters in properties dialog box. I combined several people's ideas but I could not have done it without any of them. I have tried to add notes that may be helpful for you to edit and use for your own needs.

(defun osens-on (/ selset ss_count blocklist entity blockname object ssout bph nob esb v vval sal salnth count)
(setvar "cmdecho" 0)
(setq ssout nil) ; zeroes out any prior instance of ssout
(vl-load-com)
(setq selset (ssget "X" '((0 . "INSERT"))))
(setq ss_count 0 blocklist '("os-cedt" "os-codt" "os-cous" "os-coir" "os-wst")) ; searches entire dwg for all instances of these blocks
(while (setq entity (ssname selset ss_count))
(setq object (vlax-ename->vla-object entity))
(if (vlax-property-available-p object 'effectivename)
(progn
(setq blockname (vla-get-effectivename object ))
(if (member (strcase blockname T) blocklist)
(progn
(if ssout ; creates selection set of only desired blocks
(setq ssout (ssadd entity ssout))
(setq ssout (ssadd entity))
);i
);p
);i
);p
);i
(setq ss_count (1+ ss_count))
);w
(setq bph 0)
(setq nob (sslength ssout))
(repeat nob ; evaluates each member of ssout one at a time
(setq esb (ssname ssout bph))
(setq obj (vlax-ename->vla-object esb))
(setq v (vla-getdynamicblockproperties obj))
(setq vval (vlax-variant-value v))
(setq sal (vlax-safearray->list vval))
(setq salnth (length sal))
(setq count 0)
(while (< count salnth)
(if (= (vlax-get-property (nth count sal) "PropertyName") "Visibility1") ; Visibility1 is my exact name of dynamic parameter
(progn
(vlax-put-property (nth count sal) "Value" "Cover ON")(princ) ; Cover ON is exact desired preset value of Visibility1
(setq count salnth)
)
(setq count (+ count 1))
)
);w
(setq bph (1+ bph))
); repeat
(setvar "cmdecho" 1)
(princ)
)
Message 18 of 18
balisteor
in reply to: PeterLange7168

Thank you for posting your finished code.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost