Hi guys,
I am working on a program to scale easier. What I want to accomplish is that you first chose two points on the drawing and then tell what this distance should be. Then you select the objects to scale. This program is written for scaling pdfs. This works pretty fine but I would like to insert some improvements.
To start I would like to be able to use a selection set. Now I have to pick every pdf myself.
The second thing I would like to do is to simplify the code. Now I have to run through the object list twice. Once to find the first pdf selected and once to use scale on every object.
The last thing I would like to be able to do is to be able to insert my _objectl directly in to the scale command. This way I don’t have to use the scaling option for every object and everything will be undone in one time.
Here is my lisp:
(defun test () (setq _blength (getdist "define base length")) (setq _wlength (getint "\ndefine wanted length")) (setq _scale (/ _wlength _blength)) (setq _objectl nil) (while (setq _object (car (entsel))) (setq _objectl (cons _object _objectl)) );while (setq _findpdf _objectl) (while _findpdf (setq _pdf (entget (car _findpdf))) (setq _findpdf (cdr _findpdf)) );while (setq _strtpoint (cdr (assoc 10 _pdf))) (while _objectl (setq _object (car _objectl)) (setq _objectl (cdr _objectl)) (command "scale" _object "" _strtpoint _scale ) );while );defun
Thanks in advance!
Regards
Thomas
Solved! Go to Solution.
Thomas,
I think I can make some improvements.
First my result:
(defun test ()
(setq sset (ssget))
(if (not sset) (exit))
(setq blength (getdist "\nSpecify base length: "))
(setq wlength (getdist "\nSpecify wanted length: "))
(setq scale (/ wlength blength))
(setq sslen (sslength sset))
(command "_.undo" "_be")
(while (> sslen 0)
(setq sslen (1- sslen) ent (ssname sset sslen))
(setq basepnt (cdr (assoc 10 (entget ent))))
(if basepnt
(command "scale" ent "" basepnt scale)
)
)
(command "_.undo" "_e")
)
This function looks a lot like the standard acad command Scale, but in stead of one basepoint, it uses the basepoint of every individual object.
Use ssget to make a selectionset in stead of entget.
In Autocad we normaly first select and than we ask to scale.
Use Specify in stead of Define, Basepoint i.s.o. Startpoint; this is more standard Acad.
Use "\n" at the start of your prompt. It makes sure that the prompt will be on the next line.
Use ": " at the end of your prompt. It makes the input on the command line better readable.
Use Undo Begin en Undo End to make sure that one Undo will undo the scaling of all your objects.
Test (if basepnt...) because not every object has a basepoint.
I scale every object apart, because I want to use every individual basepoint.
Grtz
Jan
That where some really useful tips.
I tried to adapt my one program to this and here you see the result.
However I didn’t follow you on all points.
For the base point I use only one point otherwise you have the possibility that scaled objects overlap each other.
And then I scaled all the objects together this excludes the use of undo.
And finally I changed some parameters to make sure that snaping is of and highlighting is on.
Thank you very much for the help!
Regards
Thomas
(defun c:scalepdf () ;save original settings (setq _orset nil) (setq _orset (append (list (cons "_oldsnap" (getvar "osmode"))) _orset)) (setq _orset (append (list (cons "_oldcmdecho" (getvar "cmdecho"))) _orset)) (setq _orset (append (list (cons "_oldhigh" (getvar "highlight"))) _orset)) ;make one settings (setvar "osmode" 0) (setvar "cmdecho" 0) (setvar "highlight" 1) ; Program (setq _objectl (ssget)) (setq _blength (getdist "\nSpecify base length: ")) (setq _wlength (getint "\nSpecify wanted length: ")) (setq _scale (/ _wlength _blength)) (setq _pdf (entget (ssname _objectl (1- (sslength _objectl))))) (setq _strtpoint (cdr (assoc 10 _pdf))) (command "scale" _objectl "" _strtpoint _scale ) ; load old settings (setvar "osmode" (cdr (assoc "_oldsnap" _orset))) (setvar "cmdecho" (cdr (assoc "_oldcmdecho" _orset))) (setvar "highlight" (cdr (assoc "_oldhigh" _orset))) );defun
My apologys for reopening this old post but my question leans very close to my first one. I would like to also add the pdfattache command. So I can in one time insert and scale the pdf.
The problem is that the pdfattache command works with a specific window and I don’t know how to include this in my lisp.
Is there somebody who knows his way around this problem?
Regards
Thomas
Thomas,
If you want to scale a group of objects with a relative scale, you don't need lisp.
Standard Autocad does this job.
It would go like this:
Command: Activate Scale
Select objects: User selects one or more objects.
Select Objects: Press <Enter> to finish selecting.
Specify base point: Give base point.
Specify scale factor or [Copy/Reference]: Type r <Enter>.
Specify reference length <1.0000>: Type @ (= lastpoint = basepoint).
Specify second point: Specify second point. The distance from basepoint to second point is reference length.
Specify new length or [Points] : Type new length.
If you want to make a macro in a toolpalette or in a menu command, the macro should look like this:
^C^Cselect;\;scale;p;;\r;@
For info about menumacro's: look in the help > customizeation guide.
Gr.
Jan.
Thomas,
When you want to combine pdfattach with scale, you can use a menumacro.
Befor you make the macro, you can simulate it by use of the Autocad command lines. Then you will understand the macro better.
In Italic you find the Autocad prompts.
Command: Type: -pdfattach <Enter>
Path to PDF file to attach: Type : ~ <Enter>Dialog select file.
Enter page number or [?] <1>: Press <Enter>.
Specify insertion point: Specify insertionpoint with your mouse.
Specify scale factor or [Unit] <1>: Press <Enter>.
Specify rotation <0>: Press <Enter>.
Command: Type: scale <Enter>.
Select objects: Type: last <Enter>
Select objects: Press <Enter>
Specify base point: Type @ <Enter>.
Specify scale factor or [Copy/Reference]: Type: r <Enter>.
Specify reference length <80.4592>: Type @ <Enter>.
Specify second point: Klick at endpoint of your PDFimage.
Specify new length or [Points] <106.6002>: Type in new length or click new length.
In menumacro this would be:
^C^C-pdfattach;~;;\;;scale;l;;@;r;@;
I hope this is what you need.
Gr.
Jan