Author Topic: Scale Block to an Attribute Within that Block  (Read 2386 times)

0 Members and 2 Guests are viewing this topic.

Bob

  • Guest
Scale Block to an Attribute Within that Block
« on: May 23, 2006, 06:01:27 AM »
Hi there,

I've got a problem and I'm hoping that somebody can help....

Our title blocks are are a block called "REG".

The title, scale, filename etc are populated by the central registration system.

I'm wanting to write a lisp to interrogate the block REG, look at the tag "R11" (which is the scale) then scale REG to that value.

I have looked for hours on google and here but I can't seem to find a solution.

I am a lisp virgin so please be gentle with me.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Scale Block to an Attribute Within that Block
« Reply #1 on: May 23, 2006, 07:56:35 AM »
Questions:
How did you want to select the block(s)?
Is there more than one block in the drawing?
How is the scale represented? Number or string, (numbers 1/4"  0.25 48) (string "1:20" "SCALE 1/4\" = 1'" "1/4\" = 1'")
Scale for x,y,z  (1,1,1) or 1 1 1

Pseudo Code
Get the blocks
Read attr R11
If in scale range, put scale in block
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Scale Block to an Attribute Within that Block
« Reply #2 on: May 23, 2006, 08:53:37 PM »
Here's some ideas bashed out quick --

Code: [Select]
(defun c:ScaleInsertsByAttrib
   
    (   /
        unlockedLayers
        insertSpec
        attribSpec
        attribValue
    )

   ;|================================================================= 
    |
    |  From http://www.theswamp.org/index.php?topic=10244.0
    |
    |================================================================= 
    |
    |  Bob wrote --
    |
    |     Hi there,
    |
    |     I've got a problem and I'm hoping that somebody can help ...
    |
    |     Our title blocks are are a block called "REG".
    |
    |     The title, scale, filename etc are populated by the central
    |     registration system.
    |
    |     I'm wanting to write a lisp to interrogate the block REG,
    |     look at the tag "R11" (which is the scale) then scale REG to
    |     that value.
    |
    |     I have looked for hours on google and here but I can't seem
    |     to find a solution.
    |
    |     I am a lisp virgin so please be gentle with me.
    |
    +-----------------------------------------------------------------
    |
    |  psuedo code
    |      initialize program specs
    |      gather unlocked layer names
    |      for each insertObject matching spec (on unlocked layer)
    |          for each attribObject matching spec
    |              if attribTextString value numerical then
    |                  scale insertObject by said value
    |
    |=================================================================|;

    ;;
    ;;  initialize ye program specs
    ;;

    (setq
        insertSpec "REG"
        attribSpec (strcase "R11") ;; strcase used to underscore intent
    )
   
    ;;
    ;;  gather ye unlocked layer names
    ;;
   
    (setq unlockedLayers
        (   (lambda ( / result )
                (vlax-for layer
                    (vla-get-layers
                        (vla-get-activedocument
                            (vlax-get-acad-object)
                        )
                    )
                    (if (eq :vlax-false (vla-get-lock layer))
                        (setq result
                            (cons
                                (vla-get-name layer)
                                result
                            )
                        )
                    )
                )
                result
            )
        )   
    )
   
    ;;
    ;;  for each insertObject matching spec (on unlocked layer)
    ;;

    (foreach insertObject

        (   (lambda ( insertSpec lockedLayers / ss i result )
                (if
                    (and unlockedLayers
                        (setq ss
                            (ssget "x"
                                (append
                                   '((0 . "insert"))
                                    (list (cons 2 insertSpec))
                                   '((66 . 1))
                                   '((-4 . "<or"))
                                    (mapcar
                                       '(lambda (layerName)
                                            (cons 8 layerName)
                                        )
                                        unlockedLayers
                                    )
                                   '((-4 . "or>"))
                                )
                            )
                        )
                    )   
                    (repeat (setq i (sslength ss))
                        (setq result
                            (cons
                                (vlax-ename->vla-object
                                    (ssname ss (setq i (1- i)))
                                )   
                                result
                            )
                        )
                    )
                )
                result
            )
            insertSpec
            lockedLayers
        )

        ;;
        ;;  for each attribObject matching spec
        ;;

        (foreach attribObject

            (   (lambda ( insertObject attribSpec / data ename result )
                    (vl-remove-if-not
                       '(lambda ( attribObject )
                            (wcmatch
                                (strcase
                                    (vla-get-tagstring
                                        attribObject
                                    )
                                )
                                attribSpec
                            )
                        )
                        (vlax-invoke insertObject 'GetAttributes)
                    )
                )
                insertObject
                attribSpec
            )

            ;;
            ;;  if attribValue numerical then
            ;;

            (if (setq attribValue
                    (distof     
                        (vla-get-textstring attribObject)
                    )
                )

                ;;
                ;;  scale insert by attribValue (uniform scaling assumed)
                ;;

                (   (lambda ( insertObject scaleFactor )
                        (foreach scaleProperty
                           '(   xscalefactor
                                yscalefactor
                                zscalefactor
                            )
                            (vlax-put-property
                                insertObject
                                scaleProperty
                                scaleFactor
                            )
                        )
                    )
                    insertObject
                    attribValue
                )
            )   
        )
    )

    (princ)
   
)

You get to add the warning prompts for blocks on locked layers, non numerical attribute values, a more robust distof function (hint: search the swamp) ...

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Bob

  • Guest
Re: Scale Block to an Attribute Within that Block
« Reply #3 on: May 25, 2006, 03:05:52 AM »
Hey that's brilliant MP. It will give me a starting point.

To answer your question, Cab, there is always 1 block.

The R11 tag is represented by "1:4" or "1:500" or various scales.

Drawings are always metric. Title blocks are always inserted at 0,0.

Our title sheet is attached with the titles populated. (A1 scale 1:1) Given this base title sheet I would want the lisp to look at the tag R11 to determine the scale factor and scale the block "REG" to that scale.

Other niceties would be to set dimscale and ltscale (1/2 scale)

« Last Edit: May 25, 2006, 03:31:52 AM by Bob »

Amsterdammed

  • Guest
Re: Scale Block to an Attribute Within that Block
« Reply #4 on: May 25, 2006, 03:48:41 AM »
Bob,
a totally different approach.

If you( your company) would use Paperspace in the proper way, your titleblock would be always scaled 1"1 and the drawing in the viewport would be scaled by the Value of R11.

Advantage: More than one scale can be printed on one sheet (details, elevations...).

Bernd

Bob

  • Guest
Re: Scale Block to an Attribute Within that Block
« Reply #5 on: May 25, 2006, 04:01:26 AM »
Thanks Amsterdammed,

But I'm struggling to tell the dinosaurs to to use grips and associative dimensions.

I tried to roll out paperspace 6 years ago. It fell on stoney ground.....

Good idea though.

Bob

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Scale Block to an Attribute Within that Block
« Reply #6 on: May 25, 2006, 07:15:45 AM »
I have to agree with Bernd, you're doing a lot of unnecessary calisthenics. It's worth adopting -- today.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst