Jump to content

Recommended Posts

Posted

I am trying to figure or understand, how to write a routine that would change the cannoscale in modelspace and then the viewport scale in paperspace.

 

Currently, I am writing it in simple method. Any idea how I can consolidate the code?

 

(defun C:1-10 ()
    (command "_model")
    (command "_.cannoscale" "1\" = 10'")
    (command "-layout" "Set" "")
    (command "_mspace")
    (command "_zoom" "extents")
    (command "_ZOOM" "Scale" "1/10xp")
    (command "_pspace")
(princ))


(defun C:1-20 ()
    (command "_model")
    (command "_.cannoscale" "1\" = 20'")
    (command "-layout" "Set" "")
    (command "_mspace")
    (command "_zoom" "extents")
    (command "_ZOOM" "Scale" "1/20xp")
    (command "_pspace")
(princ))


(defun C:1-30 ()
    (command "_model")
    (command "_.cannoscale" "1\" = 30'")
    (command "-layout" "Set" "")
    (command "_mspace")
    (command "_zoom" "extents")
    (command "_ZOOM" "Scale" "1/30xp")
    (command "_pspace")
(princ))


(defun C:1-40 ()
    (command "_model")
    (command "_.cannoscale" "1\" = 40'")
    (command "-layout" "Set" "")
    (command "_mspace")
    (command "_zoom" "extents")
    (command "_ZOOM" "Scale" "1/40xp")
    (command "_pspace")
(princ))


(defun C:1-50 ()
    (command "_model")
    (command "_.cannoscale" "1\" = 50'")
    (command "-layout" "Set" "")
    (command "_mspace")
    (command "_zoom" "extents")
    (command "_ZOOM" "Scale" "1/50xp")
    (command "_pspace")
(princ))

thank you.

Posted

Those "command" calls can be combined.

Setting system variables is cleaner than "command" calls in lisp.

Set TILEMODE to 1 to go to Model tab, then set TILEMODE to 0 to return to previous Layout.

I've used a toggle for TILEMODE for doing that for many years.

To switch to Paper Space

(vla-put-mspace (vla-get-activedocument (vlax-get-acad-object)) :vlax-false)

Back to Model Space

(vla-put-mspace (vla-get-activedocument (vlax-get-acad-object)) :vlax-true)

For Zoom Extents try 

(vla-zoomextents (vlax-get-acad-object))

You made need to unlock and relock the viewports as well, he's some old code as an example:

;(command "-layout" "set" "" "zoom" "extents" "regenall" "mspace" "zoom" "scale" "1/10xp" "_pspace" "_model" "_.cannoscale" "1\" = 10'" "-layout" "set" "")
;(princ))

(defun c:1-10( / acadObj acadDoc vp vpLock)
(setq acadObj (vlax-get-acad-object)
      acadDoc (vla-get-activedocument acadObj)
)
(setvar 'tilemode 1)
(setvar 'cannoscale "1\" = 10'")
(setvar 'tilemode 0)
(vla-Put-MSpace (vla-Get-ActiveDocument acadObj) :vlax-False)
(vla-ZoomExtents acadObj)
(vla-Put-MSpace (vla-Get-ActiveDocument acadObj) :vlax-True)
(setq vp (vla-get-activePviewport acadDoc)
      vpLock (vla-get-DisplayLocked vp)
)
(vla-put-DisplayLocked vp :vlax-False)
(vla-put-CustomScale vp 0.1)
(vla-put-DisplayLocked vp vpLock)
(princ)
)

 

Posted

Thank you for your explanation. I no its prob the wrong way to do it, but I thought command was similar to scripting and it was easier for me to follow.

 

I do have another question.

 

How would you write this so I do not have to repeat the code for each scale? Maybe where it would ask what scale and you type it in; but its one piece rather than having the same code multiple times just with the different scale?

 

Thanks

Posted

The 

C:

after defun allows you to run it from the command line but doesn't allow arguments to the function.

I have a lot of macros in my custom CUI that use the same code but are called with different arguments.

You could start you lisp with something like

(defun 1-*0(scale / CustomScale acadObj acadDoc vp vpLock)
(setq acadObj (vlax-get-acad-object)
      acadDoc (vla-get-activedocument acadObj)
)
    (cond
      ((eq scale "1\" = 10'")(setq CustomScale 0.1)
      ((eq scale "1\" = 20'")(setq CustomScale 0.05)
      ((eq scale "1\" = 40'")(setq CustomScale 0.025)
      ((eq scale "1\" = 50'")(setq CustomScale 0.02)
    )

Then call it with something like

(1-*0 "1\" = 10'")

In your code for this example use

(setvar 'cannoscale scale)

to set the annotation scale and

(vla-put-CustomScale vp CustomScale)

to set the CustomScale.

 

There's other ways but that's how I normally do it.

Rather than remembering hundreds of lisp commands all the lisp I have is organized in my custom CUI.

 

You  could also create a lisp that lets you pick the scale you want from a list after you start it which could start from the command line without arguments.

Posted

Or type (sc-defun 10)   (scale-defun 20) etc

 

(defun sc-defun (scale / CustomScale acadObj acadDoc vp vpLock)

(cond
      ((= scale 10)(setq CustomScale 0.1)

 

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