TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: stsevedallas on April 17, 2006, 02:44:09 PM
-
I need a lisp or lisps to match properties for blocks.
When I select a "source block", I will select multiple destination
blocks to match scale, colors, linetype, rotation, text style,
etc...everything.
Thanks
-
(if (setq SrcBlk (car (ensel "\nSelect source block: ")))
(setq SrcLst (entget SrcBlk)
SelSet (ssget "X" (list
(assoc 41 SrcLst) ;X-scale
(assoc 42 SrcLst) ;Y-Scale
(assoc 43 SrcLst) ;Z-scale
(assoc 50 SrcLst) ;Rotation
(assoc 62 SrcLst) ;Optional color
(assoc 6 SrcLst) ;Optional linetype
)
)
)
)
All other properties are not block specific...
-
I tried that code and it come back and says...
"no function definition: ENSEL"
It basically did not run.
Aside from that, I need it to keep allowing me to select destination blocks until finished (or cancelled like match properties)
Thank you for the reply.
-
I tried that code and it come back and says...
"no function definition: ENSEL"
It basically did not run.
Aside from that, I need it to keep allowing me to select destination blocks until finished (or cancelled like match properties)
Thank you for the reply.
typo, change ensel to entsel
Gary
-
I tried that code and it come back and says...
"no function definition: ENSEL"
It basically did not run.
Hint:
C:\< AutoCAD installation >\Help\acad_dev.chm
-
typo, change ensel to entsel
Hint:
C:\< AutoCAD installation >\Help\acad_dev.chm
Thanks guys, I shouldn't write answers late in the night of a holiday... :ugly:
-
"entsel" took care of that, however...
I now get this error,
"Error: bad SSGET list"
-
May need a vl-remove nil ??
-
Methinks the intent of this posters question was missed ... it appears as though the lisp posted will simply select all of the blocks with the same properties as the one selected. What I presume the user wants is something a little more .. such as "select a block" then select other blocks to match to the original selected block .. i.e. if the original block has a scale of 2 and the selected block has a scale of 5, it will be modified to 2.
-
You are correct Keith.
"May need a vl-remove nil ??"
What is that?
Forgive my ignorance all.
Let me review the premise for this routine, just to make certain it is understood:
1. select a "source" block
2. select a destination block to match scale, rotation, color,linetype,etc. layer too.
3. keep selecting destination blocks until finished (not all blocks, just a few select ones)
note:would work like [match properties] does.
-
I see, something like this?
;; Match Block
;; Matches properties from doner block to selected blocks
(defun c:matchblock (/ srcblk ensel srcobj prop blkobj blk color linetype
rotation x-scale y-scale z-scale
)
(if (setq srcblk (car (entsel "\nSelect source block: ")))
(setq srcobj (vlax-ename->vla-object srcblk)
x-scale (vla-get-xscalefactor srcobj)
y-scale (vla-get-yscalefactor srcobj)
z-scale (vla-get-zscalefactor srcobj)
rotation (vla-get-rotation srcobj)
color (vla-get-color srcobj)
linetype (vla-get-linetype srcobj)
)
)
(while (progn
(prompt "\nSelect Block to update: ")
(setq blk (ssget "+.:E:S"))
)
(setq blkobj (vlax-ename->vla-object (ssname blk 0)))
(prompt "\*** Got one. ***")
(vla-put-xscalefactor blkobj x-scale)
(vla-put-yscalefactor blkobj y-scale)
(vla-put-zscalefactor blkobj z-scale)
(vla-put-rotation blkobj rotation)
(vla-put-Color blkobj color)
(vla-put-Linetype blkobj linetype)
)
(princ)
)
(prompt "\*** Match Block Loaded, Enter MatchBlock to run. ***")
(princ)
Be aware that some blocks are created with 0,0 as the insert point and may cause results that are unexpected.
This is because they will rotate and scale from 0,0 and not from a point on the block.
-
Oh, here are some other properties that you may want to change as well.
; Layer = "F1_WINDOWS"
; Linetype = "ByLayer"
; LinetypeScale = 1.0
; Lineweight = -1
; PlotStyleName = "ByLayer"
-
I added the last four parameters and get..."Error: ActiveX Server returned an error: Parameter not optional"
Before the addition of the last four it worked perfectly.
Here is the code:
;; Match Block
;; Matches properties from doner block to selected blocks
(defun c:mb (/ srcblk ensel srcobj prop blkobj blk color linetype
rotation x-scale y-scale z-scale layer linetypescale lineweight plotstylename
)
(if (setq srcblk (car (entsel "\nSelect source block: ")))
(setq srcobj (vlax-ename->vla-object srcblk)
x-scale (vla-get-xscalefactor srcobj)
y-scale (vla-get-yscalefactor srcobj)
z-scale (vla-get-zscalefactor srcobj)
rotation (vla-get-rotation srcobj)
color (vla-get-color srcobj)
linetype (vla-get-linetype srcobj)
layer (vla-get-layer srcobj)
linetypescale (vla-get-linetypescale srcobj)
lineweight (vla-get-lineweight srcobj)
plotstylename (vla-get-plotstylename srcobj)
)
)
(while (progn
(prompt "\nSelect Block to update: ")
(setq blk (ssget "+.:E:S"))
)
(setq blkobj (vlax-ename->vla-object (ssname blk 0)))
(prompt "\*** Got one. ***")
(vla-put-xscalefactor blkobj x-scale)
(vla-put-yscalefactor blkobj y-scale)
(vla-put-zscalefactor blkobj z-scale)
(vla-put-rotation blkobj rotation)
(vla-put-Color blkobj color)
(vla-put-Linetype blkobj linetype)
(vla-put-layer blkobj layer)
(vla-put-linetypescale blkobj linetypescale)
(vla-put-lineweight blkobj lineweight)
(vla-put-plotstylename blkobj plotstylname)
)
(princ)
)
(prompt "\*** Match Block Loaded, Enter MB to run. ***")
(princ)
<code tags added>
-
"plotstylename" was the problem.
I took it out and everything works fine.
Thank you all for the help.
-
"plotstylename" was the problem.
I took it out and everything works fine.
Thank you all for the help.
I haven't run the code, but I see a typo-bug with the plostylename variable:
...
plotstylename (vla-get-plotstylename srcobj)
...
...
(vla-put-plotstylename blkobj plotstylname)
...
-
And the status of dynamic blocks...?
-
I am running Autocad 2004.
It is my understanding that dynamic blocks are new to 2006.
With that said, I do not know about how it would act with such entities.
-
Good catch Steve.... lost the e 8-)
-
I am running Autocad 2004.
It is my understanding that dynamic blocks are new to 2006.
With that said, I do not know about how it would act with such entities.
This will help in getting the props for dblocks.
By Peter Jamtgaard
Gary
-
Good catch Steve.... lost the e 8-)
How ironic. I need to check my postings for typos too! (see below) :ugly:
I haven't run the code, but I see a typo-bug with the plostylename variable:
-
Well when I debug and the error isn't obvious I check the spelling.
For I have clumsy fingers & no spelling skill. 8-)