Jump to content

Rectangle to viewports LISP help:How do you increase the overall scale of a viewport.


3dwannab

Recommended Posts

See screenshot of what my routine does.

It creates new vports from closed LWpolylines and locks them.

 

I just don't know how to do the same as this below.

How to do this.jpg

 

GIF of Routine:

giphy.gif

 

CODE:

;; ----------------------=={ VP_Clip_All_LWPS }==-------------------------
;; -----------------------------------------------------------------------

;; AUTHOR & ADDITIONAL CODE
;; Author:					3dwannab, Copyright © 2018.
;; Error functions:			LeeMac Help pages. www.lee-mac.com.

;; ABOUT / NOTES
;; Creates new VIEWPORT/s from existing closed LWPOLYLINE/s.

;; FUNCTION SYNTAX
;; Short-cut				VP_CALLS
;; Long-cut					VP_Clip_All_LWPS

;; VERSION					DATE			INFO
;; Version 1.0				27-07-2018		Initial release.

;; TO DO LIST
;; Increase the overall scale of the VIEWPORT from 1:20 to 1:2 for example.

;; -----------------------------------------------------------------------
;; ------------------=={ VP_Clip_All_LWPS START }==-----------------------

(defun c:---VP_Clip_All_LWPS (/) (progn (LOAD "VP_Clip_All_LWPS") (C:VP_Clip_All_LWPS)))

(defun c:VP_CALLS () (c:VP_Clip_All_LWPS))
(defun c:VP_Clip_All_LWPS (/
ent_vp
i
ss_1
var_cmde
var_os
y
)

(setq *error* LM:error)
(LM:startundo)

(setq var_cmde (getvar "cmdecho"))
(setq var_os (getvar "osmode"))
(setvar 'cmdecho 0)
(setvar 'osmode 0)

(cond ((> (getvar 'CVPORT) 1) (princ "\n ** Command not allowed in Model Tab ** "))
(
	(while
		(not
			(and
				(setq
					ent_vp (car (entsel "\nPlease select 1 VIEWPORT,\nthen any closed LWPOLYLINES within to create\nnew VPs from\n: --------------------------------------------------------- :\n"))
					ent_vp_data (if ent_vp (entget ent_vp))
					)
				(= (cdr (assoc 0 ent_vp_data)) "VIEWPORT")
				(progn
					(if	(setq ss_1 (ssget '((0 . "LWPOLYLINE") (-4 . "=") (70 . 1))))
						(progn
							(command "_.vports" "_lock" "_on" ent_vp "")
							(command "_.copybase" '(0 0) ent_vp "")
							(entdel ent_vp)
							(repeat
								(setq i (sslength ss_1))
								(command "_.pasteclip" "_non" '(0 0))
								(setq ent_last (entlast))
								(command "_.vpclip" ent_last (ssname ss_1 (setq i (1- i))))
								)
							(repeat
								(setq y (sslength ss_1))
								(command "_.vpclip" (ssname ss_1 (setq y (1- y))) "_D")
								)
							)
						(progn
							(princ "\n***  Nothing Selected  ***\n")(princ)
							)
						)
					)
				)
			)
		(princ (strcat "\n   >>>   " (itoa (setq ss_1_len (sslength ss_1))) (if (> ss_1_len 1) " new viewports have been created" " new viewport has been created") "   <<<   \n"))
		)
	)
)
(*error* nil)(princ)
(princ)
)

;; -----------------------------------------------------------------------
;; ---------------------=={ Functions START }==---------------------------

(vl-load-com)

(defun LM:error (errmsg)
(and acDoc (vla-EndUndoMark acDoc))
(and errmsg
	(not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
	(princ (strcat "\n<< Error: " errmsg " >>\n"))
	)
(setvar 'cmdecho var_cmde)
(setvar 'osmode var_os)
) (princ)

(defun LM:startundo ()
(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))
) (princ)

;; -----------------------------------------------------------------------
;; -----------------------=={ Functions END }==-- ------------------------

(princ "\nVP_Clip_All_LWPS.lsp loaded | Version 1.0 | by 3dwannab.\n")
(princ "\nType \"VP_Clip_All_LWPS\" OR \"VP_CALLS\" to run.\n") (princ)

;; -----------------------------------------------------------------------
;; --------------------=={ VP_Clip_All_LWPS END }==-----------------------
;; EOL

Link to comment
Share on other sites

Hi there. There is no out of the box way, but you could do it using doslib's dos_popupmenu function.

You have to manually build and manage the list of choices (list of strings), a list of integers to indicate which strings is enable/disable/checked, and it returns an integer which is the index # of the selection made within the list. After that you would have to go from lets say 2 to retrieve the expression "1:5", and then from that string actually change the scale of the viewport accordingly. You would also need to install dos_lib on each computer, and ideally have some work around for your code to execute and work even if dos_lib is not installed on a given computer. It is indirectly doable, but expect to go from a code of 25 lines to maybe 250. Cuter, but a lot more expensive. (like women) :shock:

 

img.png

 

You can look at doslib page here...

(shoutout to mcneel! :))

Link to comment
Share on other sites

Hi, thanks. But I was referring to the scale pickbox that appears when you select a viewport. What command is there to change that. I think this only appeared in 2019.

 

I could then just use an initget to display the scales I require.

Link to comment
Share on other sites

I was referring to the scale pickbox that appears when you select a viewport. What command is there to change that. I think this only appeared in 2019.

Change that... how?? The pickbox that appears on your gif after clicking the triangle? it is exactly the same as the one I have shown you. It is new that they added that for viewports, but it has been the standard scale pickbox for viewbases since like 2013. The pickbox is just a GUI, probably made in c#, and you need a way to access it. As far as I know you cant using plain lisp, unless you have something like dos_lib, with which you can interact using lisp, but is not bound and limited to Autocad's inner lisp interpreter, and can use the available resources of its native language (c#?) and interact with it. From my understanding, the lisp function (like dos_popmenu) is just a wrapper of their c# function.

 

The only lisp level GUI is DCL, and very limited/archaic. As for what is done behind once a user picked a choice in the scale pickbox is entirely something else. Again, you could do it, but you would have to exactly mimic its behavior, to the last detail... a lot of things append under the hood when you pick a scale. Way more than meets the eye.

 

As far as I know, that pickbox it is not available to interact out of the box, and is not a lisp thing. Maybe .net can do it natively? (it might still be only a c# wrapper function too)... anyway. I'm sorry if I totally misunderstood your question (or you totally misunderstood my answer). :shock:

 

ps.: I would probably go with something like 2nd choice (initget)

Link to comment
Share on other sites

No, you get it (I think). I was really hoping for some built in command/method to control the viewport like that. Not to control the UI element of that pickbox.

Link to comment
Share on other sites

Why not make your own a simple DCL list box choice.

 

;; List Box - Lee Mac

;; Displays a DCL list box allowing the user to make a selection from the supplied data.

;; msg - [str] Dialog label

;; lst - [lst] List of strings to display

;; bit - [int] 1=allow multiple; 2=return indexes

;; Returns: [lst] List of selected items/indexes, else nil

Link to comment
Share on other sites

If you look at a vport it has an item called Customscale which will return a number than can be re interpreted to a scale. A zoom e returns CustomScale = 3.72752 a 1 is 1:1000 a 2 is 1:500 and so on this is for metric. Turn on the "viewports" toolbar and you will see what I am talking about the number will change as you zoom within the viewport, you can enter a number in this toolbar and the zoom scale will change, basicly doing what your after.

Link to comment
Share on other sites

Turn on the "viewports" toolbar
Yes, I've known how to zoom into a viewport at such a scale since R14. ;)

 

Thing is, this new pickbox in 2019 controls the scale of the viewport AND the size, meaning you never have to resize a viewport scaled from 1:10 to 1:2 anymore. AC takes care of that. I just don't think this command is exposed yet.

Link to comment
Share on other sites

Well then i'd suggest using vlisp... That will change both the scale and size at the same time without the need for fancy cross products operations derivated from the height and such to control the geometry.

(vlax-invoke-method vlobject 'scaleentity (vlax-3d-point '(0 0 0)) 2)

The vlax-3d-point is the base point of the scale operation. You could also use the vport center property like that

(vlax-invoke-method vlobject 'scaleentity (vlax-get-property vlobject 'center)2)

Will still need a cross product from the prop 'customscale to calculate the scale factor.... (and for info changing 'customscale changes only the scale within the vport without changing the vport outline, so scaleentity would be my golden choice here)

:thumbsup:

Link to comment
Share on other sites

(vlax-invoke-method vlobject 'scaleentity (vlax-get-property vlobject 'center)2)

 

Thanks, that's what I was after. I haven't really looked at methods of vlisp before.

 

I'm nearly there now. But, I've searched a few places and there's no clear way of setting the VP's annotation scale the same as the CustomScale which obv is a division of the scale/1.

 

Perhaps if I CANNOSCALE with the viewport active and then use your 2nd method above along with setting the CustomScale also, it might do that trick.

 

9 times out of 10, I'm scaling from 1:10 to 1:2.

Link to comment
Share on other sites

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