TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: stsevedallas on April 17, 2006, 02:44:09 PM

Title: match properties for blocks
Post 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

Title: Re: match properties for blocks
Post by: Jürg Menzi on April 17, 2006, 04:29:36 PM
Code: [Select]
(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...
Title: Re: match properties for blocks
Post by: stsevedallas on April 17, 2006, 05:14:08 PM
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.
Title: Re: match properties for blocks
Post by: GDF on April 17, 2006, 05:29:41 PM
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
Title: Re: match properties for blocks
Post by: Mark on April 17, 2006, 07:45:29 PM
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
Title: Re: match properties for blocks
Post by: Jürg Menzi on April 18, 2006, 02:53:57 AM
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:
Title: Re: match properties for blocks
Post by: stsevedallas on April 18, 2006, 08:46:44 AM
"entsel" took care of that, however...
I now get this error,
"Error: bad SSGET list"
Title: Re: match properties for blocks
Post by: CAB on April 18, 2006, 08:50:12 AM
May need a vl-remove nil  ??
Title: Re: match properties for blocks
Post by: Keith™ on April 18, 2006, 09:03:02 AM
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.
Title: Re: match properties for blocks
Post by: stsevedallas on April 18, 2006, 09:10:31 AM
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.
Title: Re: match properties for blocks
Post by: CAB on April 18, 2006, 10:00:33 AM
I see, something like this?
Code: [Select]
;;  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.
Title: Re: match properties for blocks
Post by: CAB on April 18, 2006, 10:02:53 AM
Oh, here are some other properties that you may want to change as well.
Code: [Select]
;   Layer = "F1_WINDOWS"
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   PlotStyleName = "ByLayer"
Title: Re: match properties for blocks
Post by: stsevedallas on April 18, 2006, 11:02:40 AM
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:

Code: [Select]
;;  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>
Title: Re: match properties for blocks
Post by: stsevedallas on April 18, 2006, 11:16:29 AM
"plotstylename" was the problem.
I took it out and everything works fine.
Thank you all for the help.
Title: Re: match properties for blocks
Post by: Sdoman on April 19, 2006, 06:41:57 AM
"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)
...
 
Title: Re: match properties for blocks
Post by: Crank on April 19, 2006, 07:15:10 AM
And the status of dynamic blocks...?
Title: Re: match properties for blocks
Post by: stsevedallas on April 19, 2006, 11:41:26 AM
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.
Title: Re: match properties for blocks
Post by: CAB on April 19, 2006, 12:53:52 PM
Good catch Steve.... lost the e  8-)
Title: Re: match properties for blocks
Post by: GDF on April 19, 2006, 01:57:37 PM
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
Title: Re: match properties for blocks
Post by: Sdoman on April 19, 2006, 02:54:06 PM
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:
 
Title: Re: match properties for blocks
Post by: CAB on April 19, 2006, 04:08:20 PM
Well when I debug and the error isn't obvious I check the spelling.
For I have clumsy fingers & no spelling skill.   8-)