Jump to content

Recommended Posts

Posted

First off, I do not have nay experience in using macros or lisp in autocad yet.

 

I have 500 tree symbols in a drawing. Each tree symbol is snapped to a point (in the center). The tree's are all on their own layer.

 

I need to replace the tree symbol with the same symbol but scaled x 2 (so it is twice as big). However I need the larger tree symbol to then be centered back on that original point in the center. Is there some way to automate this, using macros or lisp and if so can I please get an explanation as how to do this.

 

I manually done it for about 100 on Friday and it took a while.

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    7

  • Organic

    7

  • dbroada

    6

  • lpseifert

    2

Top Posters In This Topic

Posted

I believe this could be achieved quite easily with LISP, but I have a few questions first:

 

Is the tree symbol a block?

 

If so, could you post a sample of the block please (in 2000 format :) )

Posted

I would also suggest asking a moderator to move this thread to the AutoLISP and VBA Customisation forum, as you will probably get more of a response for it there.

 

Having said that:

 

Don't post another thread in that forum - having duplicate threads for the same thing gets messy, and you don't get the answer any quicker.

Posted

I've got a bit of time right now, so here's a starter for you:

 

(defun sclblk (bNme / ss)
 (vl-load-com)
 (if (and (tblsearch "BLOCK" BNme)
      (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 BNme)
            (if (getvar "CTAB") (cons 410 (getvar "CTAB"))
              (cons 67 (- 1 (getvar "TILEMODE"))))))))
   (progn
     (setq ss (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss))))
     (foreach e ss (vla-ScaleEntity e (vla-Get-InsertionPoint e) 2.0)))
   (princ "\n<!> No Blocks Found <!>")))

(defun c:test ()
 (sclblk "[color=Red][b]TREE BLOCK[/b][/color]")
 (princ))

Just change the part that says "TREE BLOCK" to whatever your block is called.

 

This will scale the block by a factor of 2, with base point as the insertion point of the block.

 

To run the function, load the modified LISP and type "test" in the command line.

Posted

As the scaling function is defined as a sub-function, you can scale multiple block names at the same time.

 

There are different ways to do this, maybe:

 

(defun sclblk (bNme / ss)
 (vl-load-com)
 (if (and (tblsearch "BLOCK" BNme)
      (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 BNme)
            (if (getvar "CTAB") (cons 410 (getvar "CTAB"))
              (cons 67 (- 1 (getvar "TILEMODE"))))))))
   (progn
     (setq ss (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss))))
     (foreach e ss (vla-ScaleEntity e (vla-Get-InsertionPoint e) 2.0)))
   (princ "\n<!> No Blocks Found <!>")))

(defun c:test ()
 (sclblk "[color=Red][b]TREE BLOCK[/b][/color]")
 (sclblk "[b][color=Red]TREE BLOCK2[/color][/b]")
 (sclblk "[b][color=Red]TREE BLOCK3[/color][/b]")
 (princ))

 

As above, multiple blocks can be scaled by repeatedly invoking the sub-function,

or, more succinctly:

 


(defun sclblk (bNme / ss)
 (vl-load-com)
 (if (and (tblsearch "BLOCK" BNme)
      (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 BNme)
            (if (getvar "CTAB") (cons 410 (getvar "CTAB"))
              (cons 67 (- 1 (getvar "TILEMODE"))))))))
   (progn
     (setq ss (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss))))
     (foreach e ss (vla-ScaleEntity e (vla-Get-InsertionPoint e) 2.0)))
   (princ "\n<!> No Blocks Found <!>")))

(defun c:test ()
 (mapcar 'sclblk '("[b][color=Red]TREE BLOCK[/color][/b]" "[b][color=Red]TREE BLOCK2[/color][/b]" "[b][color=Red]TREE BLOCK3[/color][/b]"))
 (princ))

 

By using the mapcar function to map the characteristics of the sub-function to every element in the provided list.

 

Hope this explains things a little better

 

If you have any further questions or queries, just ask :)

 

Cheers

 

Lee

Posted

Ok i'll give that a try tomorrow thanks. It is a block, although the block is not at the scale I need. i.e. i scaled it after importing into the drawing and now wish to scale that scaled block by 2x. So I guess i'll just cretae another block from that.

 

Where do I save the program (directory) and what file extension do I save it as? How do I then load this into autocad?

Posted

if its 500 insertions of the same block it could also be done by just redefining the block. No programming required and all get done in one go.

 

 

edit...

 

alternatively you could have QSELECTed them all and just changed the X,Y scale in properties.

Posted

I can't edit that block (don't have permission).

Posted

then how does the LISP help? Its not doing anything different to what I have suggested.

Posted
I can't edit that block (don't have permission).

 

If you don't have the permissions to edit the block yourself, you probably won't have permission to use the LISP that I posted. :(

 

For future reference, with LISP files, copy all the code into a new notepad doc and save the doc as filename.lsp make sure that you have the filetype set to "all files".

 

Then, in ACAD, go to load Application (under Tools), or type _appload at command line.

 

Load the saved LISP, and type test to run it.

Posted

Sorry for not being clear enough. I can load the block and edit it, although not save to the default master block file (although can create another copy block of it etc).

 

Thanks for the instructions on how to use lsp, I'll try this at work tomorrow.

Posted

in that case you can just REFEDIT or BEDIT the block within your drawing and scale it by 2. Close the editor and all your blocks will be redefined.

Posted

I get what you're saying in theory, although just ain't so sure it will work in practice. However it certainly soudns great if it works, so will try it first.

Posted

Try selecting all the blocks you want to scale (Qselect, filter, Layiso...). Once selected, in Properties you can change their scale factor.

Posted

Can you please explain: Qselect, filter, Layiso

Posted

Qselect and Filter are commands for selective object selection. Type Qselect or Filter at the command line, they're fairly intuitive, there is also a Help button. Layiso is an Express command to isolate a layer, making selection of objects on that layer easier.

Posted
I get what you're saying in theory, although just ain't so sure it will work in practice. However it certainly soudns great if it works, so will try it first.
its worked that way since I first used AutoCAD, no reason to think its suddenly stopped. It depends what you have done and what you want the end result to be. If you want all the blocks to become scale 2:1 I would use my second method, the one that lpsifert has now also explained, if you want the blocks to be twice as big but at 1:1 scale I would rescale the block.
Posted

Editing the blocks worked a treat thanks. Placing a point in their centre, scaling and moving it back to the point. Saved me a lot of time thanks.

Posted

and this shows the wisdom of setting the insertion point of a block in a sensible position when the block is defined.

Posted

I should really think a little outside the box, instead of resorting to LISP programs whenever I get faced with something of this nature... I can never see the "simple" answer :P

 

Nice one Dave,

 

Lee

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...