Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Scale pdf

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
Anonymous
680 Views, 9 Replies

Scale pdf

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

 

9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: Anonymous

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

 

Message 3 of 10
devitg
in reply to: Anonymous

Please accept my apologies , what is it , or you call a PDF , on a DWG .? As English it is not my born language. Could you upload a DWG , 2008, or less, please, to see it? Thanks
Message 4 of 10
Anonymous
in reply to: Anonymous

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

 

Message 5 of 10
Anonymous
in reply to: Anonymous

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

Message 6 of 10
Anonymous
in reply to: Anonymous

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.

 

Message 7 of 10
Anonymous
in reply to: Anonymous

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

 

Message 8 of 10
Anonymous
in reply to: Anonymous

Hi Jan, That is really interesting and is certainly something worth trying. But I have one little question: Correct me if I am wrong but with macro’s you simply use commands the same way you use them in AutoCAD. So this is exactly what you basically do with lisp when u use the command function? I am asking these questions because with lisp I can save some information that would be handy later. And I am wondering of this is also possible with AutoCAD. For example I would like wile inserting the pdf be able to choose the type of ducts I am going to use. Based on this decision some blocks will be enabled and some would be disabled. Are these things that can be done with macro’s? Regards Thomas
Message 9 of 10
devitg
in reply to: Anonymous

Please tell me since what acad version it can be inserted a PDF.

 

 

Message 10 of 10
devitg
in reply to: devitg

It is an auto reply , I got the solution . by searching for "INSERT PDF" http://usa.autodesk.com/adsk/servlet/u/gsearch/results?siteID=123112&catID=123155&id=2088334&qt=%22i...

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost