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

How to get the viewport scale via lisp?

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Gordon_S
6710 Views, 8 Replies

How to get the viewport scale via lisp?

I am adapting a routine by Alan J Thompson found here for placing an outline of a paperspace viewport in modelspace.

 

I have added some lines for making a suitable Noplot layer with appropriate linetype, and wanted to make the lwpolyline have a thickness dependent upon the viewport scale.

 

My paperspace viewport scales are set for printing via Zoom - 1/50XP for example to get a 1:50 scale plot (or 0.02XP)

 

Having selected the relevant viewport, I wanted to be able to determine the vp scale, but am unsure how to extract this information from the viewport entity itself.

 

I did receive help some time in the past for a similar matter, but I'm not sure that I can use it in the same way. The routine was as follows:-

(defun xpfact ()
   (- (car (trans '(1 0 0) 2 3))
      (car (trans '(0 0 0) 2 3))
   )
)

 

--

Gordon

8 REPLIES 8
Message 2 of 9
Gordon_S
in reply to: Gordon_S

I've just seen in the DXF Group Codes for Viewports the comment at the bottom of the list that says:

Note  The ZOOM XP factor is calculated with the following formula: group_41 / 2nd_group_1040 (or pspace_height / mspace_height).

 

However, although I understand what has to be accessed and the nature of the calculation, I do not know how to get hold of the '2nd_group_1040' which appears to be xdata.

 

What code do I need to access the second 1040 group from the list of xdata?

--

Gordon

Message 3 of 9
phanaem
in reply to: Gordon_S

Hi Gordon

 

The code from your first post is working if you are in PaperSpace. But if there are multiple viewports with different scale, I don't know for which one is returning the correct answer (something related to ActiveVieport or so).

Try this instead

(if
  (setq ss (ssget ":E:S" '((0 . "VIEWPORT"))))
  (vla-get-CustomScale (vlax-ename->vla-object (ssname ss 0)))
  )

 

 

Message 4 of 9
Gordon_S
in reply to: phanaem

Hi phanaem,

 

Thanks for your code.

 

I've added this in to my routine and it works perfectly.

 

--

 

Gordon

Message 5 of 9
Edwin.Saez
in reply to: Gordon_S

@Gordon_S,

maybe you could share the lisp, since I'm needing as it is to select the vieport and zoom it 1000 / 100XP.

Value 100, would be the scale that would change depending on what you need.

 

thanks

Edwin Saez


LinkedIn / AutoCAD Certified Professional


EESignature



 


Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.

Message 6 of 9

Hi Edwin,

 

I have found the lisp that I adapted slightly , originally by Jimmy Bergmark.

I have it as vp-outline.lsp dated 18 Sept 2003 - you are lucky that I am still around and getting feeds/notifications.




Message 7 of 9

@gordonstephens20,

Thanks for sharing the lisp. I think the code needs to be updated, because it does not work in autocad 2018. The command does not do anything.

Edwin Saez


LinkedIn / AutoCAD Certified Professional


EESignature



 


Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.

Message 8 of 9

Sorry, I have been retired for 6 years now so have not used it in quite a while - also, I do not have Acad 2018.

You may have to ask for some help to tweak it - I think that it has been too long for me to unpick it and work out why it doesn't do anything.
Message 9 of 9
DannyNL
in reply to: Edwin.Saez

The command DOES work in AutoCAD 2018, but only to the use as stated in the comment section at the top.

In a Layout (!) you start the command and select a viewport; the routine then draws a polyline boundary in modelspace (!) to indicate the viewport boundary.

 

So for scaling and other settings this routine needs to be updated to specifically suite your needs.

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

Post to forums  

Autodesk Design & Make Report

”Boost