ibnut Posted August 24, 2011 Share Posted August 24, 2011 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. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2011 Share Posted August 24, 2011 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. Quote Link to comment Share on other sites More sharing options...
DANIEL Posted August 24, 2011 Share Posted August 24, 2011 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? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2011 Share Posted August 24, 2011 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)? Quote Link to comment Share on other sites More sharing options...
DANIEL Posted August 24, 2011 Share Posted August 24, 2011 What LISP would that be the one your going to write! 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. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2011 Share Posted August 24, 2011 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. Quote Link to comment Share on other sites More sharing options...
DANIEL Posted August 24, 2011 Share Posted August 24, 2011 couldn't part of the script be to go through and set them all to read/write? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2011 Share Posted August 24, 2011 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. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2011 Share Posted August 24, 2011 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! Quote Link to comment Share on other sites More sharing options...
DANIEL Posted August 24, 2011 Share Posted August 24, 2011 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. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2011 Share Posted August 24, 2011 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. Quote Link to comment Share on other sites More sharing options...
ibnut Posted August 24, 2011 Author Share Posted August 24, 2011 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? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2011 Share Posted August 24, 2011 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 Quote Link to comment Share on other sites More sharing options...
Guest kruuger Posted August 24, 2011 Share Posted August 24, 2011 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 Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2011 Share Posted August 24, 2011 Awesome, Kruuger! See, I know very little about manipulating with tblobjname, and will have to look up DXF 330. Edit: (kr:BLK_SetBlockUnits '("[color=red]<BlockName1>[/color]" "[color=red]<BlockName2>[/color]" "[color=red]<BlockName3>[/color]") acInsertUnitsInches) Quote Link to comment Share on other sites More sharing options...
ibnut Posted August 24, 2011 Author Share Posted August 24, 2011 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 24, 2011 Share Posted August 24, 2011 See, I know very little about manipulating with tblobjname, and will have to look up DXF 330. 330 references the parent entity, but there is no need to convert from Vanilla: (vla-put-units (vla-item <Block Collection> <Block name>) <units>) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 24, 2011 Share Posted August 24, 2011 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) ) ) Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2011 Share Posted August 24, 2011 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 LoL You'd laugh, I searched Apropos for InsUnits, instead of only a partial string "units" Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 24, 2011 Share Posted August 24, 2011 :beer: Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.