Jump to content

How do you check the existence of a Viewport Scale with lisp?


Recommended Posts

Posted

Autocad Civil 3D 2010.

 

I am attempting to import a set of viewport scales into a drawing via lisp. The problem is that when I reset the scalelist, it only loads the civil scales. I need the architectural scales as well.

 

I can load the scales individually very easily, like this:

(command "-scalelistedit" "add" "1/16\" = 1'-0\"" "0.0625:12" "e");

 

However, if that scale already exists, scalelistedit needs slightly different options, so the script halts.

 

I am looking for something like:

 

(if (tblsearch "ViewportScale" "3/22\" = 1'-0\"")

(command "-scalelistedit" "add" "3/32\" = 1'-0\"" "Y" "0.0938:12" "e")

(command "-scalelistedit" "add" "3/32\" = 1'-0\"" "0.0938:12" "e")

)

 

However, I can't find a list of valid tables to search anywhere, so I cannot even verify that the tblsearch command will work here.

 

Any suggestions?

Posted

Perhaps before I get too far down a bad path, what is the standard method for automatically bringing viewport scales into a drawing in Acad 2010?

Posted

I am not sure, I use the viewport toolbar for the most part, But I believe it sets zoom percentage.

Posted

I hope this sends you in the right direction.

 

From Acad Help Section

 

Properties of Viewport

 

Displays the properties of the selected layout viewport. 
Property name
(by category) 

[b]Description [/b]
[b];[/b]
[b]Geometry [/b]
[b]Center X[/b]
[b]Center Y[/b]
[b]Center Z[/b]
Specifies the X,Y,Z coordinate values for the center of the viewport Width Specifies the width of the viewport; the width of a viewport is the X axis measurement of the area within a viewport frame Height Specifies the height of the viewport; the height of a viewport is the Y axis measurement of the viewport frame 
[b];[/b]
[b]Misc [/b]
[b]On[/b] Determines whether the viewport is on or off 
[b]Clipped[/b] Determines whether viewport clipping is on or off 
[b]Display locked[/b] Determines whether viewport locking is on or off 
[color=magenta][b]Standard scale[/b] Specifies the standard scale for the viewport[/color] 
[color=magenta][b]Custom scale[/b] [/color][color=magenta]Specifies a custom scale for the viewport [/color]
[b]UCS per viewport[/b] Determines whether the UCS is saved with the viewport or not 
[b]Shade Plot[/b] Specifies how views are plotted 

Posted

To be clear, I'm not trying to set the scale of an individual viewport. I'm trying to populate the list of available viewports which is available at the bottom of the window, and the list which you can edit by hand by running the "Scalelistedit" command.

Posted

Hi Matt,

 

This function may help you check what scales are present:

 

(defun GetScaleList (/ dic l)
 (vl-load-com)
 ;; Lee Mac  ~  25.03.10
 
 (if (not (vl-catch-all-error-p
            (setq dic (vl-catch-all-apply
                        (function vla-item)
                          (list (vla-get-Dictionaries
                                  (vla-get-ActiveDocument
                                    (vlax-get-acad-object))) "ACAD_SCALELIST")))))
   (vlax-for scl dic
     (setq l (cons (cdr (assoc 300 (entget (vlax-vla-object->ename scl)))) l))))
 l)

 

 

Another:

 

(defun GetScaleList (/ dic)
 (vl-load-com)
 ;; Lee Mac  ~  25.03.10

 (if (setq dic (dictsearch (namedobjdict) "ACAD_SCALELIST"))
   (mapcar
     (function
       (lambda (x) (cdr (assoc 300 (entget (cdr x))))))
     (vl-remove-if-not
       (function
         (lambda (x) (= 350 (car x)))) dic))))

Posted

if you were to use Lee Mac's 2nd offering in post #6 above with the following you can populate the scale list. You'll need to edit the following to suit your needs for architectural scales though, similar to your example in post #1.

(setq scllst (getscalelist))
     (if (not (member'"1\" = 1'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 1'" "1:1"))
   (if (not (member'"1\" = 2'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 2'" "1:2" "e"))
    (if (not (member'"1\" = 3'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 3'" "1:3" "e")) 
    (if (not (member'"1\" = 4'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 4'" "1:4" "e"))
    (if (not (member'"1\" = 5'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 5'" "1:5" "e")) 
    (if (not (member'"1\" = 10'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 10'" "1:10" "e"))
    (if (not (member'"1\" = 20'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 20'" "1:20" "e"))
    (if (not (member'"1\" = 30'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 30'" "1:30" "e"))
    (if (not (member'"1\" = 40'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 40'" "1:40" "e"))
    (if (not (member'"1\" = 50'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 50'" "1:50" "e"))
    (if (not (member'"1\" = 60'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 60'" "1:60" "e"))
    (if (not (member'"1\" = 80'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 80'" "1:80" "e"))
    (if (not (member'"1\" = 100'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 100'" "1:100" "e"))
    (if (not (member'"1\" = 150'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 150'" "1:150" "e"))
    (if (not (member'"1\" = 200'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 200'" "1:200" "e"))
    (if (not (member'"1\" = 400'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 400'" "1:400" "e"))
    (if (not (member'"1\" = 500'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 500'" "1:500" "e"))
    (if (not (member'"1\" = 2000'" scllst))(vl-cmdf "-scalelistedit" "a" "1\" = 2000'" "1:2000" "e"))

Posted

Perhaps a slightly more compact way to phrase that Larry :)

 

(setq scllst (getscalelist))

(mapcar
 (function
   (lambda (name ratio)
     (if (not (vl-position name scllst))
       (vl-cmdf "_.-scalelistedit" "_a" name ratio "_e"))))

 '("1\" = 1'" "1\" = 2'" "1\" = 3'")
 '(  "1:1"       "1:2"      "1:3"  ))

Posted

Much nicer... I've gotta learn and get a handle on mapcar & lambda

I did the above a while ago for a specific problem- it worked so I quit.

Posted

Just think of lambda as any other subfunction, and mapcar operates with it as normal :)

 

We could rewrite the above as:

 

(defun checkScale (name ratio)
 (if (not (vl-position name scllst))
   (vl-cmdf "_.-scalelistedit" "_a" name ratio "_e")))

(setq scllst (getscalelist))

(mapcar 'checkScale

 '("1\" = 1'" "1\" = 2'" "1\" = 3'")
 '(  "1:1"       "1:2"      "1:3"  ))

Posted

Thanks for that...

I guess (defun is used when the function will be used somewhere else and (lambda when the function is used only once?

also...

When/why is (function sometimes required with (lambda ?

Posted
I guess (defun is used when the function will be used somewhere else and (lambda when the function is used only once?

 

Something along those lines, yes.

 

When/why is (function sometimes required with (lambda ?

 

The function function is not required at all, but interpretation is quicker than the apostrophe. I end up using it everywhere.

 

(alert
 (vl-list->string
   (mapcar (function (lambda (x) (boole 6 x 95)))
           (vl-string->list "\023\026\014\017x618\1776,\177<003"))))

  • 2 weeks later...
Posted

@Lee Mac and lpseifert

 

Thank you very much, that is exactly what I was looking for. I added this script to my acaddoc.lsp file, and I won't have to worry about looking for scales ever again! (at least, not until the next Autocad comes out, and breaks something else!)

 

Thanks again!

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