Create Annotation Scales Using List

Create Annotation Scales Using List

ebsoares
Collaborator Collaborator
2,191 Views
4 Replies
Message 1 of 5

Create Annotation Scales Using List

ebsoares
Collaborator
Collaborator

Hi, everyone.

Wondering if someone can help me generate a lisp code to add scales to the annotative scale list (using the -scaleListEdit command) by iterating through a list as the one below:

 

(setq myScaleList
    (list
        "scaleName1" "1:1"
        "scaleName2" "1:5"
"scaleName3" "1:10" ) )

 

The -scaleListEdit command asks for the name and then the ratio of the scale, so I don't think the foreach function would help me there. I though of using the mapcar function, but is seems to returns a list (I haven't used that function before, so can't be sure)...

I would prefer to stick to a single list, as shown on the sample code above. Perhaps another option would be a single list of multiple lists, like so:

 

(setq myScaleList
    (list
        (list "scaleName1" "1:1")
        (list "scaleName2" "1:5")
(list "scaleName3" "1:10") ) )

 

Any help or guidance would be appreciated!

 

0 Likes
Accepted solutions (1)
2,192 Views
4 Replies
Replies (4)
Message 2 of 5

cadffm
Consultant
Consultant
Accepted solution

Foreach repeat while mapcar, all works, it's just the question how to create the code inside.

 

But it is simpler with a dotted pair list:

(setq myScaleList
    '(
        ("scaleName1" . "1:1")
        ("scaleName2" . "1:5")
("scaleName3" . "1:10") ) )

(foreach i myscalelist
(Command .. (car i) (cdr i))
)

And what is if your scales are present and you run this?


These scales are standard scales?
Then you can also use the reset option and edit the system scale list,
you will find that list in your options.



Sebastian

0 Likes
Message 3 of 5

ebsoares
Collaborator
Collaborator

Thank you, Sebastian! It worked just as I would have liked it to 😊

In regards to whether a particular scale already exists, I am using another piece of code that checks for that and, if it does exist it doesn't do anything.

For those in need, here the full code:

;
; --------------------------------------------------------------------------------------------------
; ---------------------------------------- User Functions ------------------------------------------
; --------------------------------------------------------------------------------------------------
;
; Main user call:
(defun C:AnnoScale ( / myScaleList)
    (setq myScaleList             ; Using dotted pair list
        '(                        ; "scale name" . "scale ratio"
            ("scaleName1" . "1:1")
            ("scaleName2" . "1:5")
            ("scaleName3" . "1:10")
        )
    )
    (addScales myScaleList)
    (princ)
)
;
; --------------------------------------------------------------------------------------------------
; ------------------------------------ Main Code (Do Not Edit) -------------------------------------
; --------------------------------------------------------------------------------------------------
;
; Main Code:
(defun addScales (scaleList / cmde i)
    ; Begin silent mode:
    (setq cmde (getvar 'cmdecho)) ; Store cmdEcho variable
    (setvar 'cmdecho 0)
    
    ; iterate through each item in the list:
    (foreach i scaleList
        (if (not (checkScale (car i)))    ; if the scale does not already exist
            (progn
                (command "-ScaleListEdit" "Add" (car i) (cdr i) "e")
                (princ (strcat "\nAdded " (car i) " to list"))
            )
            (princ (strcat "\nScale " (car i) " already in list"))
        )
    )
    
    ; Restore cmdEcho mode:
    (setvar 'cmdecho cmde)
    (princ)
)
;
; Checks whether scale exist. Returns nil if not, or the full data if it does
; Sample call: (checkScale "1/8\" = 1'-0\"")
; Source code: https://www.theswamp.org/index.php?topic=46328.0 (reply #11)
(defun checkScale  (scaleName / )
    (car
        (vl-remove-if-not
            (function (lambda (item) (eq scaleName (cdr (assoc 300 item)))))
            (mapcar (function (lambda (item) (entget (cdr item))))
                (vl-remove-if-not
                    (function (lambda (item) (= (car item) 350)))
                    (dictsearch (namedobjdict) "ACAD_SCALELIST")
                )
            )
        )
    )
)

Thanks again, @cadffm  👍🏼

Message 4 of 5

owitzki
Enthusiast
Enthusiast

Just wondering if this can be simplified.

For added scale list...

....

;
(defun C:M75 ( / myScaleList)
(command "measurement" "1")
(command "-scalelistedit" "r" "y" "e")
(setq myScaleList ; Using dotted pair list
'( ; "scale name" . "scale ratio"
("1:75" . "1:75")
)
)
(addScales myScaleList)
(princ)
(command "cannoscale" "1:75")
)
;
(defun C:M125 ( / myScaleList)
(command "measurement" "1")
(command "-scalelistedit" "r" "y" "e")
(setq myScaleList ; Using dotted pair list
'( ; "scale name" . "scale ratio"
("1:125" . "1:125")
)
)
(addScales myScaleList)
(princ)
(command "cannoscale" "1:125")
)
;
(defun C:M150 ( / myScaleList)
(command "measurement" "1")
(command "-scalelistedit" "r" "y" "e")
(setq myScaleList ; Using dotted pair list
'( ; "scale name" . "scale ratio"
("1:150" . "1:150")
)
)
(addScales myScaleList)
(princ)
(command "cannoscale" "1:150")
)
;
(defun C:M200 ( / myScaleList)
(command "measurement" "1")
(command "-scalelistedit" "r" "y" "e")
(setq myScaleList ; Using dotted pair list
'( ; "scale name" . "scale ratio"
("1:200" . "1:200")
)
)
(addScales myScaleList)
(princ)
(command "cannoscale" "1:200")
)
;
(defun C:M300 ( / myScaleList)
(command "measurement" "1")
(command "-scalelistedit" "r" "y" "e")
(setq myScaleList ; Using dotted pair list
'( ; "scale name" . "scale ratio"
("1:300" . "1:300")
)
)
(addScales myScaleList)
(princ)
(command "cannoscale" "1:300")
)
(defun C:M400 ( / myScaleList)
(command "measurement" "1")
(command "-scalelistedit" "r" "y" "e")
(setq myScaleList ; Using dotted pair list
'( ; "scale name" . "scale ratio"
("1:400" . "1:400")
)
)
(addScales myScaleList)
(princ)
(command "cannoscale" "1:400")
)
(defun C:M500 ( / myScaleList)
(command "measurement" "1")
(command "-scalelistedit" "r" "y" "e")
(setq myScaleList ; Using dotted pair list
'( ; "scale name" . "scale ratio"
("1:500" . "1:500")
)
)
(addScales myScaleList)
(princ)
(command "cannoscale" "1:500")
)

;
;
; --------------------------------------------------------------------------------------------------
; ------------------------------------ Main Code (Do Not Edit) -------------------------------------
; --------------------------------------------------------------------------------------------------
;
; Main Code:
(defun addScales (scaleList / cmde i)
; Begin silent mode:
(setq cmde (getvar 'cmdecho)) ; Store cmdEcho variable
(setvar 'cmdecho 0)

; iterate through each item in the list:
(foreach i scaleList
(if (not (checkScale (car i))) ; if the scale does not already exist
(progn
(command "-ScaleListEdit" "Add" (car i) (cdr i) "e")
(princ (strcat "\nAdded " (car i) " to list"))
)
(princ (strcat "\nScale " (car i) " already in list"))
)
)

; Restore cmdEcho mode:
(setvar 'cmdecho cmde)
(princ)
)
;
; Checks whether scale exist. Returns nil if not, or the full data if it does
; Sample call: (checkScale "1/8\" = 1'-0\"")
; Source code: https://www.theswamp.org/index.php?topic=46328.0 (reply #11)
(defun checkScale (scaleName / )
(car
(vl-remove-if-not
(function (lambda (item) (eq scaleName (cdr (assoc 300 item)))))
(mapcar (function (lambda (item) (entget (cdr item))))
(vl-remove-if-not
(function (lambda (item) (= (car item) 350)))
(dictsearch (namedobjdict) "ACAD_SCALELIST")
)
)
)
)
)

Thanks to ebsoares, sebastian and CADffm

0 Likes
Message 5 of 5

Sea-Haven
Mentor
Mentor

Why would you just not provide the scale as a question enter scale, the only thing different in the scale is the "1:" added to it. "1:xxx". Have say a (defun c:addscale. I know I answer lots using my radio buttons but you could have all the scales preset and just pick. 1:300, if metric is an odd scale and normally not used as you have to buy special scale rules. Yeah I know do not scale.

 

(defun C:addscale ( / myScaleList)
(setq sc  (getstring "\nEnter scale "))
(setq sc2 (strcat "1:" sc))
(command "measurement" "1")
(command "-scalelistedit" "r" "y" "e")
(setq myScaleList
(list
(cons "scale name" "scale ratio")
(cons sc sc2)
)
)
)