Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Contributor
macuma
Posts: 27
Registered: ‎07-09-2008
Message 1 of 12 (256 Views)

Check uniform scale blocks

256 Views, 11 Replies
03-26-2009 07:27 AM
I have written a lisp routine to insert blocks in drawings The syntax used is:-

(command "insert" ins_point x_scale y_scale rotation att1 att2)

This was working fine but problems started to occur on certain files. The y scale was being used for the rotation value and the rotation value was being used for the first attribute value. On investigation I found that the blocks in these files had been set to uniform scale.

Is there a way I can change the uniform scale for the block before invoking the insert command or checking for uniform scale and running different insert commands depending on the result of the check?

I have tried running a tblsearch on the block with it set uniformly and non uniformly and cannot find a difference. I have also checked the codes on the block insertions by running (entget (car (entesl)) in both files but cannot find a difference.
Active Contributor
macuma
Posts: 27
Registered: ‎07-09-2008
Message 2 of 12 (256 Views)

Re: Check uniform scale blocks

03-30-2009 03:52 AM in reply to: macuma
I have found a workaround for the problem.

I wblocked the block. Went into the file and changed it to non uniform scale.

In my code I now do an insert = and pull in the new block which changes the existing block from uniform scale to non uniform.
*Joe Burke
Message 3 of 12 (257 Views)

Re: Check uniform scale blocks

03-30-2009 07:07 AM in reply to: macuma
Belated reply...

You can check whether a block definition allows non-uniform scaling or not by looking
at the BlockScaling property. And you can change that property if need be.

Joe Burke
Active Contributor
macuma
Posts: 27
Registered: ‎07-09-2008
Message 4 of 12 (257 Views)

Re: Check uniform scale blocks

03-30-2009 08:07 AM in reply to: macuma
Thanks Joe.

Sorry if I'm being a bit slow here but what is the command/syntax for this. I've looked through the developers help file and not found anything.
*Joe Burke
Message 5 of 12 (257 Views)

Re: Check uniform scale blocks

03-30-2009 09:37 AM in reply to: macuma
Assuming the is known and it is a valid block name, something like this:

(setq *blocks* (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))))
(setq blkdef (vla-item *blocks* ))
(if (= 0 (vlax-get blkdef 'BlockScaling))
(print "block may be non-uniormly scaled.")
(print "block may not be non-uniormly scaled.")
)
Active Contributor
macuma
Posts: 27
Registered: ‎07-09-2008
Message 6 of 12 (257 Views)

Re: Check uniform scale blocks

03-31-2009 07:10 AM in reply to: macuma
Thanks Joe.
*Joe Burke
Message 7 of 12 (257 Views)

Re: Check uniform scale blocks

04-02-2009 09:13 AM in reply to: macuma
You're welcome.
Valued Contributor
jcourtne
Posts: 94
Registered: ‎03-02-2010
Message 8 of 12 (78 Views)

Re: Check uniform scale blocks

05-21-2014 07:48 AM in reply to: macuma

I was not able to get the posted solution to work.

Doing a vlax-dump object on my block I do not see the scaled uniformly property either.

This is the result of a dump from a dynamic block that is uniformly scaled. However, sometimes i need to know whether the block i'm inserting is uniformly scaled before it is even defined on the drawing. Meaning i'll have to check that blocks dwg file from running lisp. Thats way beyond what i can do currently. 

If anyone comes up with something else please post. :smileyhappy:

 

; IAcadBlockReference2: AutoCAD Block Reference Interface
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00000001406191d8>
;   Document (RO) = #<VLA-OBJECT IAcadDocument 000000002c5b40e0>
;   EffectiveName (RO) = "BD_EQ"
;   EntityTransparency = "ByLayer"
;   Handle (RO) = "316"
;   HasAttributes (RO) = -1
;   HasExtensionDictionary (RO) = -1
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 0000000031d0f4c8>
;   InsertionPoint = (21.25 22.125 0.0)
;   InsUnits (RO) = "Inches"
;   InsUnitsFactor (RO) = 1.0
;   IsDynamicBlock (RO) = -1
;   Layer = "0"
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Material = "ByLayer"
;   Name = "*U4"
;   Normal = (0.0 0.0 1.0)
;   ObjectID (RO) = 42
;   ObjectID32 (RO) = 42
;   ObjectName (RO) = "AcDbBlockReference"
;   OwnerID (RO) = 43
;   OwnerID32 (RO) = 43
;   PlotStyleName = "ByLayer"
;   Rotation = 0.0
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 0000000031d0f9a0>
;   Visible = -1
;   XEffectiveScaleFactor = 1.0
;   XScaleFactor = 1.0
;   YEffectiveScaleFactor = 1.0
;   YScaleFactor = 1.0
;   ZEffectiveScaleFactor = 1.0
;   ZScaleFactor = 1.0
; Methods supported:
;   ArrayPolar (3)
;   ArrayRectangular (6)
;   ConvertToAnonymousBlock ()
;   ConvertToStaticBlock (1)
;   Copy ()
;   Delete ()
;   Explode ()
;   GetAttributes ()
;   GetBoundingBox (2)
;   GetConstantAttributes ()
;   GetDynamicBlockProperties ()
;   GetExtensionDictionary ()
;   GetXData (3)
;   Highlight (1)
;   IntersectWith (2)
;   Mirror (2)
;   Mirror3D (3)
;   Move (2)
;   ResetBlock ()
;   Rotate (2)
;   Rotate3D (3)
;   ScaleEntity (2)
;   SetXData (2)
;   TransformBy (1)
;   Update ()

*Expert Elite*
Kent1Cooper
Posts: 5,364
Registered: ‎09-13-2004
Message 9 of 12 (70 Views)

Re: Check uniform scale blocks

05-21-2014 09:25 AM in reply to: jcourtne

jcourtne wrote:

... sometimes i need to know whether the block i'm inserting is uniformly scaled before it is even defined on the drawing. Meaning i'll have to check that blocks dwg file from running lisp. ....


If the Block is going to be inserted at uniform scales, and the only reason to check on whether it's defined for uniform scaling is to know whether to supply both X and Y scale factors in an Insert command, then you can eliminate the issue by using the Scale option in the command.  It asks for a scale factor, and applies the same one to all axes, so you can supply it once, and it doesn't matter how many it would ask for if you weren't using that option:

 

(command "_.insert" "_scale" YourScale YourInsertionPoint ....

Kent Cooper
*Expert Elite*
dbroad
Posts: 1,546
Registered: ‎08-16-2007
Message 10 of 12 (63 Views)

Re: Check uniform scale blocks

05-21-2014 09:48 AM in reply to: jcourtne

Kent is right.  It is easy to avoid the issue when all scale factors are the same.

 

You were checking the block reference object (an insert), not a block object.  This is one way to check if a block is uniformly scaled.

(vl-load-com)
;;DCB Returns true if the block is defined with
;;a uniform scale.
(defun isuniform (blockname)
  (if (tblobjname "block" blockname)
    (= acUniform
       (vla-get-blockscaling
	 (vla-item
	   (vla-get-blocks
	     (vla-get-activedocument
	       (vlax-get-acad-object)
	       )
	     )
	   blockname
	   )
	 )
       )
    )
  )

 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.