PDA

View Full Version : Visibility State reporting in existing Block List routine


4Micah
2005-05-20, 05:02 PM
Hello All, I am fairly new to the LISPing world and need a little help updating an old LISP routine that my company has been using.

As it stands the routine analyzes the selection set and reports, to the Text Window, the Quantity of each block it finds. Allowing us to quckly generate an equipment list, this routine has worked perfectly in the past. However, as we have introduced Dynamic Blocks with Visibility Parameters - the routine generates some oddball results. For the second instance of any block that utilizes the new Visibility state Parameter - a new name seems to be being generated for it (i.e. *U55).

To avoid these unexpected items in the report I am wondering if there is a way to put an IF/THEN type statement in this routine that would first test if the block has a Visibility Parameter being utilized, and if so, would then report the Visibility State for that block as opposed to the (generated) block name.

I am including the existing .lsp routine if anyone can help me.

peter
2005-05-21, 07:37 PM
Well Joel,

You picked a pretty difficult question to ask, it took me a while to connect the two block references together. Actually there is "xdata" on the block definition of the anonymous block in the blocks table that includes the "handle" of the block definition that corresponds to it.

To get it out was kinda tricky, but here we go.

If you pass the entity name of the block to this function it will return the "real name"

substitute (setq BNAME (getrealname ENAME))
for the line (setq BNAME (cdr BNAME))
and
substitute (setq BNAME2 (getrealname ENAME))
for the line (setq BNAME2 (cdr BNAME2))

in your code and add this subroutine below your routine in the same file it should work

Peter Jamtgaard

Forgive the code formatting, for some reason the forum editor always changes the indentation.


; Written By: Peter Jamtgaard copr 2005
; Extraction of Dynamic Block Real Name from
; Anonymous block entity
; Syntax (getrealname (car (entsel)))
(defun GetRealName (entSelection /
lstEntity
lstXdata
entBlockReference2
objBlockReference
objSelection
strBlockName
strHandle
)
(setq objSelection (vlax-ename->vla-object entSelection))
(if (wcmatch (vla-get-objectname objSelection)
"AcDbBlockReference,AcDbMInsertBlock"
)
(progn
(setq strBlockName (vla-get-name objSelection))
(if (and (= (substr strBlockName 1 1) "*")
(setq objBlockReference
(vla-item
(vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
)
(vla-get-name objSelection)
)
)
(setq
lstEntity (entget (vlax-vla-object->ename objBlockReference)
(list "AcDbBlockRepBTag")
)
)
(setq lstXdata (assoc -3 lstEntity))
(setq strHandle (cdr (assoc 1005 (cdadr lstXdata))))
(setq entBlockReference2 (handent strhandle))
)
(setq strBlockName
(vla-get-name
(vlax-ename->vla-object entBlockReference2)
)
)
)
)
)
strBlockName
)






;Tip1506: BLOCKLST.LSP List Blocks (c)1999, Snehal Shah
;reformatted, verified with R2000/R14/R13
;clarified command prompts
;automated display of the text screen to view results
(defun C:BLOCKLST (/ BLKS CHK I J K L
L1 N BNAME ENAME EDATA BLIST BNUM
BNAME1 BNAME2 TEMP1 TEMP2
)
(princ "\nUse standard selection methods to ")
(setq BLKS (ssget (list (cons 0 "INSERT"))))
(setq L (sslength BLKS))
(setq L (- L 1))
(setq I 0)
(setq BLIST (list "BLOCK NAMES"))
(setq BNUM (list "INSTANCES"))
(while (<= I L)
(setq ENAME (ssname BLKS I))
(setq EDATA (entget ENAME))
(setq BNAME (assoc 2 EDATA))
(setq BNAME (getrealName ENAME))
(setq CHK (member BNAME BLIST))
(if (eq CHK NIL)
(setq BLIST (cons BNAME BLIST))
) ;_ end of if
(setq I (+ I 1))
) ; end while
(setq L1 (length BLIST))
(setq L1 (- L1 2))
(setq J 0)
(setq N 0)
(setq K 0)
(while (<= K L1)
(setq N 0)
(setq BNAME1 (nth K BLIST))
(setq J 0)
(while (<= J L)
(setq ENAME (ssname BLKS J))
(setq EDATA (entget ENAME))
(setq BNAME2 (assoc 2 EDATA))
(setq BNAME2 (getrealName ENAME))
(if (eq BNAME1 BNAME2)
(setq N (+ N 1))
) ;_ end of if
(setq J (+ J 1))
) ; end while j
(setq BNUM (cons N BNUM))
(setq K (+ K 1))
) ; end while k
;;; Formatting
(setq K 0)
(princ)
(command "TEXTSCR")
(princ "\nBlock Name Instance")
(while (<= K L1)
(setq TEMP1 (nth K BLIST))
(setq TEMP2 (nth (- L1 K) BNUM))
(princ "\n")
(princ TEMP1)
(princ "\t\t\t")
(princ TEMP2)
(setq K (+ K 1))
) ; end while k
(princ
"\n\nPress the <F2> key to hide the text screen after viewing results... "
)
(princ)
) ;_ end of defun
; Written By: Peter Jamtgaard copr 2005
; Extraction of Dynamic Block Real Name from
; Anonymous block entity
; Syntax (getrealname (car (entsel)))
(defun GetRealName (entSelection /
lstEntity lstXdata
entBlockReference2
objBlockReference objSelection
strBlockName strHandle
)
(setq objSelection (vlax-ename->vla-object entSelection))
(if (wcmatch (vla-get-objectname objSelection)
"AcDbBlockReference,AcDbMInsertBlock"
)
(progn
(setq strBlockName (vla-get-name objSelection))
(if (and (= (substr strBlockName 1 1) "*")
(setq objBlockReference
(vla-item
(vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
)
(vla-get-name objSelection)
)
)
(setq
lstEntity (entget (vlax-vla-object->ename objBlockReference)
(list "AcDbBlockRepBTag")
)
)
(setq lstXdata (assoc -3 lstEntity))
(setq strHandle (cdr (assoc 1005 (cdadr lstXdata))))
(setq entBlockReference2 (handent strhandle))
)
(setq strBlockName
(vla-get-name
(vlax-ename->vla-object entBlockReference2)
)
)
)
)
)
strBlockName
)
(princ
"\n Blocklst loaded... Start command by typing BLOCKLST "
) ;_ end of princ
(princ)

4Micah
2005-05-22, 01:56 AM
Peter, thank you so much for your help. This works beautifully!

I wonder if I could extend the favor a bit further though.
Your solution has allowed me to now see the real name as opposed to the anonymous name. Which is great! However, I was wondering for those blocks which are utilizing the Visibility Parameter if there was a way to pull the Visibility State name out of the block as opposed to the real name.

I have noticed that when you perform a LIST on one of the dynamic blocks that has had its visibility changed that the Visibility name is now reported in the list. (i.e. "Visibility: California Grab Rail") Is there anyway to grab that information out of the list somehow?

Thank you again for your help. You are a great help to those of us new to the programming game.

peter
2005-05-22, 03:54 PM
Can you send me a drawing with the block inserted into a sample drawing? so I can see what you mean?


Peter Jamtgaard

4Micah
2005-05-23, 01:39 PM
Peter,

The attatched drawing contains a block (with 6 different Visibility States). You will see that the block name is "Grab_Rail". The six different Visibility States represent different types of Grab_Rails. At different stages in the development of my drawings I sometimes change the type of Rail used. The new visibility parameter has made this process a breeze. However, when I run my Block List routine I would like to be able to see the specific Rail used (Visibility State name) as opposed to the more generic Block Name ("Grab_Rail" in this instance).

If you perform the LIST command on the block you will see the following:

BLOCK REFERENCE Layer: "W-Rail"
Space: Model space
Handle = 3248
Block Name: "Grab_Rail"
Anonymous Name: "*U45"
at point, X=277777777'-6" Y= 0'-0" Z= 0'-0"
X scale factor: 1.000
Y scale factor: 1.000
rotation angle: 0.00
Z scale factor: 1.000
InsUnits: Inches
Unit conversion: 1.000
Scale uniformly: No
Allow exploding: Yes
Position X: 0'-0"
Position Y: 0'-0"
Angle: 90.00
Visibility: California Grab Rail

Previously, when I ran my block list routine it was reporting the "*U45" (anonymous name). Your fix has now allowed me to see the "Grab_Rail" (main block name.) This is wonderful. However, I was wondering if there was a way to have the .lsp routine report the "California Grab Rail" (Visibility name) when it encounters a block utilizing different Visibility States.
Ideally the routine would report the block names as it always has - except when it encounters a dynamic block with visibility states - it will then report the visibility name for those blocks.

Again, Thank you for all your help - I could never have gotten this far on my own.

RobertB
2005-05-23, 07:57 PM
...However, I was wondering for those blocks which are utilizing the Visibility Parameter if there was a way to pull the Visibility State name out of the block as opposed to the real name.

I have noticed that when you perform a LIST on one of the dynamic blocks that has had its visibility changed that the Visibility name is now reported in the list. (i.e. "Visibility: California Grab Rail") Is there anyway to grab that information out of the list somehow?Yes, Dynamic Block properties are available via ActiveX. I wouldn't go the route you are going now to work with a DBlock's visibility parameter. The below chunk of code demonstrates how to iterate thru the DBlock properties.

(setq blkProps (rrbI:Array->List (vla-GetDynamicBlockProperties blkObj))) ; get dynamic block properties
(foreach blkProp blkProps
(cond ((= (vla-Get-Description blkProp) dynName) ; if property is for pipe dash
(vla-Put-Value blkProp dynCount)))) ; then put correct value in property

ccaron
2008-04-17, 04:34 PM
I'm doing a similar thing, however my issue is backward compatability for non-AutoCAD users. It seems in certain flavors of CAD the dynamic blocks show ALL the visibility states when converted. I found it does the same thing when I save my files as R12 DXFs.

I have been going round and round with this same problem but in VBA.

So what needs to happen is the blocks need to be converted/ to regular blocks (or exploded, don't care at this point) and convertToAnonymousBlock doesn't seem to work. I can get the xdata from the definition but my issue is trying to grab the object by using the definition information.

All help is appreciated

thanks

Chris