Jump to content

Mass Block Scaling


ibnut

Recommended Posts

I have multiple drawing files, each with multiple blocks (several have nested blocks 2-3 levels deep)... that I need to scale from metric to imperial.

 

Is it possible for a lisp/macro to open up all blocks within a drawing (disregarding block name since there are over 1000 blocks, each with varying names), scale, and change the block units property to "inches"?

 

I wanted to get a feel whether something like this would be even possible before I looked into the actual coding that would be required.

Link to comment
Share on other sites

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • BlackBox

    9

  • DANIEL

    4

  • Lee Mac

    4

  • ibnut

    3

Popular Days

Top Posters In This Topic

Using Visual LISP, the InsUnts Property is Read-Only (RO), and cannot be modified.

 

Perhaps this is possible through ENTMOD-ing the Block Definition through DXF Codes, but I am unable to determine that at this time.

 

Edit: You can successfully scale the blocks to suite the drawing, once you know the conversion factor for the desired scale, however you'd still need to modify this setting in the Block Editor.

Link to comment
Share on other sites

Using Visual LISP, the InsUnts Property is Read-Only (RO), and cannot be modified.

 

Perhaps this is possible through ENTMOD-ing the Block Definition through DXF Codes, but I am unable to determine that at this time.

 

can't you just set a macro to run the lisp?

Link to comment
Share on other sites

can't you just set a macro to run the lisp?

 

What LISP would that be, given that the InsUnits Property the OP wants to change is Read-Only (RO)? :unsure:

Link to comment
Share on other sites

What LISP would that be

 

the one your going to write! :P seriously though, I didn't mean to imply there was a lisp for this already , I was just thinking that a combo between a macro and lisp might get ibnut what there looking for.

Link to comment
Share on other sites

No worries; this is new to me, as all of our blocks are created as 'Unitless', instead of specifying 'Feet' etc.

 

I actually started writing code for this, and just after getting the framework setup, I tested a block to get the exact property name (I can't possible remember it all!), and then saw (RO) next to the property I needed >.

 

So then I opened developer documentation and skimmed the DXF codes for INSERT entity, and searched (Ctrl+F) for "ins" and "unit", and couldn't come up with anything useful. I'm actually quite disappointed by the current outcome. I don't really have time to jump into C#/VB.NET at the moment or I'd peruse the Object Viewer.

Link to comment
Share on other sites

couldn't part of the script be to go through and set them all to read/write?

 

To clarify; these Object Model Properties, like certain System Variables (i.e., RIBBONSTATE, etc.) are Read-Only and cannot be modified.

 

Visual LISP cannot modify the InsUnits Property of a Block Object using any of these:

 

([color=red]vla-put-insunits[/color] <BlockObject> <Value>)                                ; <- Function does not exist

(vlax-put <BlockObject> 'InsUnits <Value>)

(vlax-put-property <BlockObject> 'InsUnits <Value>)

 

Perhaps there exists a way to modify this property that I am unaware of via ENTMOD, or even .NET/ARX APIs?

 

The only way I know of, is to manually open the block in the Block Editor, and change this property in the Properties Pane.

Link to comment
Share on other sites

So, ibnut -

 

I can help you out with other modifications (like scaling the blocks without changing InsUnits Property), but that's about it for this request (from me). Perhaps someone smarter than I (there's lots of them!) will come along and educate me, and help you both.

 

Good luck!

Link to comment
Share on other sites

To clarify; these Object Model Properties, like certain System Variables (i.e., RIBBONSTATE, etc.) are Read-Only and cannot be modified.

 

Visual LISP cannot modify the InsUnits Property of a Block Object using any of these:

 

([color=red]vla-put-insunits[/color] <BlockObject> <Value>) ; <- Function does not exist

(vlax-put <BlockObject> 'InsUnits <Value>)

(vlax-put-property <BlockObject> 'InsUnits <Value>)

 

Perhaps there exists a way to modify this property that I am unaware of via ENTMOD, or even .NET/ARX APIs?

 

The only way I know of, is to manually open the block in the Block Editor, and change this property in the Properties Pane.

 

sounds like a lisp :)

 

my days programming are way behind me but it being nothing more than code thats in the way to begin with leads me to believe its doeable just maybe not doeable easily lol

 

hope you don't mind me poking your brain like that, just trying think outside the box a bit which is often birth place of new and useful code. :)

Link to comment
Share on other sites

No worries; I'm not sure that I'm the best person to learn how to write code from, but I'm happy to share the little code knowledge I have. :)

 

There are several areas of LISP (Auto & Visual) that I feel that Autodesk has poorly handled, System Variables too for that matter. Alas, that is a separate topic.

Link to comment
Share on other sites

So, ibnut -

 

I can help you out with other modifications (like scaling the blocks without changing InsUnits Property), but that's about it for this request (from me). Perhaps someone smarter than I (there's lots of them!) will come along and educate me, and help you both.

 

Good luck!

 

Thanks! Your help is much appreciated!

 

I'm still relatively new to writing code. Do you have a sample (or know where I can find one) of just scaling the blocks without changing InsUnits Property.. something I can use as a starting point?

Link to comment
Share on other sites

Quick example (Error checking not provided):

 

(defun c:FOO  ( / ss pt scale)
 (princ "\rMY SCALE EXAMPLE ")
 (vl-load-com)
 (if (and (setq ss (ssget "_:L:S:E" '((0 . "INSERT"))))
          (setq pt (getpoint "\nEnter base point: "))
          (setq scale (getreal "\nEnter scale factor: ")))
   (progn
     (vla-scaleentity
       (vlax-ename->vla-object (ssname ss 0))
       (vlax-3d-point pt)
       scale))
   (cond 
     (pt (prompt "\n** Scale factor required ** "))
     (ss (prompt "\n** Base point required ** "))
     ((prompt "\n** Nothing selected, or on locked layer ** "))))
 (princ))

 

^^ Copy+Paste this into your command line, and hit Enter. Then type "FOO" (without the quotes), and hit Enter... follow command prompt.

 

HTH

Link to comment
Share on other sites

Guest kruuger

maybe this will help you. it can be easy modified to change all blocks in drawing.

; ============================================================ ;
; Set block units                                              ;
;   Blks 
[list] - block(s) name                                ;
;   Units [iNT] - new block units                              ;
; ============================================================ ;
(defun kr:BLK_SetBlockUnits (Blks Units)
 (foreach % Blks
   (vla-Put-Units
     (vlax-Ename->vla-Object
       (cdr (assoc 330 (entget (tblobjname "BLOCK" %))))
     )
     Units
   )
 )
)

kruuger

BlockUnits.lsp

Link to comment
Share on other sites

Awesome, Kruuger! :beer:

 

See, I know very little about manipulating with tblobjname, and will have to look up DXF 330. :rofl:

 

Edit:

 

(kr:BLK_SetBlockUnits '("[color=red]<BlockName1>[/color]" "[color=red]<BlockName2>[/color]" "[color=red]<BlockName3>[/color]") acInsertUnitsInches)

Link to comment
Share on other sites

Thanks for the help Renderman and kruuger!

 

In both samples, I've noticed that only the top block is affected. Is there a way to get the function to apply to a block and all subsequent nested sub-blocks? I have several blocks that are not located anywhere on the drawing except within another block and these need to be scaled as well.

Link to comment
Share on other sites

See, I know very little about manipulating with tblobjname, and will have to look up DXF 330. :rofl:

 

330 references the parent entity, but there is no need to convert from Vanilla:

 

(vla-put-units (vla-item <Block Collection> <Block name>) <units>)

Link to comment
Share on other sites

e.g.

 

(vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
   (if
       (and
           (eq :vlax-false (vla-get-isxref block))
           (eq :vlax-false (vla-get-islayout block))
       )
       (vla-put-units block acInsertUnitsInches)
   )
)

Link to comment
Share on other sites

330 references the parent, but there is no need to convert from Vanilla:

 

(vla-put-units (vla-item <Block Collection> <Block name>) <units>)

 

THAT is why you-da-man :notworthy: LoL

 

You'd laugh, I searched Apropos for InsUnits, instead of only a partial string "units"

 

Double-Facepalm.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...