Lisp error rejected

Lisp error rejected

kidznok
Advocate Advocate
1,418 Views
16 Replies
Message 1 of 17

Lisp error rejected

kidznok
Advocate
Advocate

Hi
I try with lisp to reset scale list when someone will save file.
I found sth like this

(defun AtSaveCommand (calling-reactor b)
(if
(or
(= (car b) "QSAVE")
(= (car b) "SAVEAS")
(= (car b) "SAVE")
)
(command "-SCALELISTEDIT" "R" "Y" "E")
)
)

(defun loadTheSaveReactor ()
(vl-load-com)
(if *FileOnSave* (vlr-remove *FileOnSave*))
(setq *FileOnSave*
(vlr-command-reactor nil '((:vlr-commandwillStart . AtSaveCommand)))
)
)
(loadTheSaveReactor)

And i have "error no function definition:scalelistedit"

Could someone help me?

0 Likes
Accepted solutions (2)
1,419 Views
16 Replies
Replies (16)
Message 2 of 17

hak_vz
Advisor
Advisor
Accepted solution

Replace command function with vl-cmdf and it should work.

 

(defun AtSaveCommand (calling-reactor b)
(if
(or
(= (car b) "QSAVE")
(= (car b) "SAVEAS")
(= (car b) "SAVE")
)
(vl-cmdf  "-SCALELISTEDIT" "R" "Y" "E")
)
)

(defun loadTheSaveReactor ()
(vl-load-com)
(if *FileOnSave* (vlr-remove *FileOnSave*))
(setq *FileOnSave*
(vlr-command-reactor nil '((:vlr-commandwillStart . AtSaveCommand)))
)
)
(loadTheSaveReactor)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 17

kidznok
Advocate
Advocate

Thank you.
Error is gone.
But... when I use qsave or save reset scale is not working.
File is save but I have the same scale list.

When I use save I would like to reset scale and then save my file.


0 Likes
Message 4 of 17

Moshe-A
Mentor
Mentor

@kidznok  hi,

 

this will not work cause as far as i know, you can not call (command) function from callback [and that's includes (vl-cmdf) ]

 

the way to approach this is access the scalelist dictionary data and delete the unwanted scales.

 

(dictsearch (nameobjdict) "ACAD_SCALELIST")

then dig-in 

 

note that you can not delete scales that are used (the same as layers, linetypes, textstyles)

 

Moshe

 

 

0 Likes
Message 5 of 17

kidznok
Advocate
Advocate

Like this?

 

(defun AtSaveCommand (calling-reactor b)
(if
(or
(= (car b) "_QSAVE")
(= (car b) "SAVEAS")
(= (car b) "_SAVE")
)
(dictsearch (nameobjdict) "ACAD_SCALELIST")
)
)

(defun loadTheSaveReactor ()
(vl-load-com)
(if *FileOnSave* (vlr-remove *FileOnSave*))
(setq *FileOnSave*
(vlr-command-reactor nil '((:vlr-commandwillStart . AtSaveCommand)))
)
)
(loadTheSaveReactor)

Cause it's not working. Sorry, I'm not good in autolisp.

0 Likes
Message 6 of 17

ronjonp
Mentor
Mentor
Accepted solution

@kidznok 

FWIW

;; This
(defun atsavecommand (calling-reactor b)
  (if (or (= (car b) "QSAVE") (= (car b) "SAVEAS") (= (car b) "SAVE"))
    (vl-cmdf "-SCALELISTEDIT" "R" "Y" "E")
  )
)
;; Could be shortened to this
(defun atsavecommand (calling-reactor b)
  (if (wcmatch (car b) "QSAVE,SAVEAS,SAVE")
    (vl-cmdf "-SCALELISTEDIT" "R" "Y" "E")
  )
)
;; Or this
(defun atsavecommand (calling-reactor b)
  (if (wcmatch (car b) "*SAVE*")
    (vl-cmdf "-SCALELISTEDIT" "R" "Y" "E")
  )
)
0 Likes
Message 7 of 17

kidznok
Advocate
Advocate

I try and unfortunately it not work at my dwg 😕
But thank you.

0 Likes
Message 8 of 17

Moshe-A
Mentor
Mentor

@kidznok ,

 

give this a go 🤣

 

This is auto delete scales according "measurement" sysvar. if it's 0 - imperial, all metric scale is vanish

if it's 1 - metric, all imperial scale is vanish.

 

enjoy

Moshe

 

 

(vl-load-com)

(defun AtSaveCommand (calling-reactor cmd^ /  ResetScaleList ;| local function |;)

 (defun ResetScaleList (measurement / AcDbScale elist)
  (vlax-for AcDbScale (vla-item (vla-get-dictionaries (vla-get-activedocument (vlax-get-acad-object))) "ACAD_SCALELIST")
   (setq elist (entget (vlax-vla-object->ename AcDbScale)))
    
   (cond
    ((= measurement 0) ; imperial
     (if (member (cdr (assoc '300 elist)) rdata^)
      (vl-catch-all-apply 'vla-delete (list AcDbScale))
     )
    ); case
    ((= measurement 1); metric
     (if (not (member (cdr (assoc '300 elist)) rdata^))
      (vl-catch-all-apply 'vla-delete (list AcDbScale))
     )
    ); case
   ); cond

   (vlax-release-object AcDbScale) 
  ); vlax-for
 ); resetScaleList

   
 (if (wcmatch (car cmd^) "QSAVE,SAVEAS,SAVE")
  (ResetScaleList (getvar "measurement")) ; 0 - imperial, 1 - metric
 )
); AtSaveCommand


(defun loadTheSaveReactor ()
 (setq rdata^ '("1:1" "1:2" "1:4" "1:5" "1:8" "1:10" "1:16" "1:20" "1:30" "1:40" "1:50" "1:100" "2:1" "4:1" "8:1" "10:1" "100:1"))  ; metric scales  
  
 (if (not *FileOnSave*)
  (setq *FileOnSave* (vlr-command-reactor nil '((:vlr-commandwillStart . AtSaveCommand))))
 )
)

(loadTheSaveReactor)

 

 

0 Likes
Message 9 of 17

Sea-Haven
Mentor
Mentor

A possible alternative is the 2 VLR functions, rather than check every command, :vlr-commandwillStart

 

:VLR-beginSave
:VLR-beginClose

 

 

0 Likes
Message 10 of 17

Moshe-A
Mentor
Mentor

@kidznok ,

 

a shorter version, use this one 🤣

 

Moshe

 

(vl-load-com)

(defun AtSaveCommand (calling-reactor cmd^ / AcDbScale elist)
 (if (wcmatch (car cmd^) "QSAVE,SAVEAS,SAVE")
  (vlax-for AcDbScale (vla-item (vla-get-dictionaries (vla-get-activedocument (vlax-get-acad-object))) "ACAD_SCALELIST")
   (setq elist (entget (vlax-vla-object->ename AcDbScale)))
     
   (cond
    ((= (getvar "measurement") 0) ; imperial
     (if (member (cdr (assoc '300 elist)) (vlr-data calling-reactor))
      (vl-catch-all-apply 'vla-delete (list AcDbScale))
     )
    ); case
    ((= (getvar "measurement") 1); metric
     (if (not (member (cdr (assoc '300 elist)) (vlr-data calling-reactor)))
      (vl-catch-all-apply 'vla-delete (list AcDbScale))
     )
    ); case
   ); cond

   (vlax-release-object AcDbScale) 
  ); vlax-for
 ); if
); AtSaveCommand


(defun loadTheSaveReactor ()
 (if (not *FileOnSave*)
  (setq *FileOnSave* (vlr-command-reactor
		       '("1:1" "1:2" "1:4" "1:5" "1:8" "1:10" "1:16" "1:20" "1:30" "1:40" "1:50" "1:100" "2:1" "4:1" "8:1" "10:1" "100:1") ; vlr-data, metric scales  
		       '((:vlr-commandwillStart . AtSaveCommand))
		     )
  ); setq
 ); if
); loadTheSaveReactor 

(loadTheSaveReactor)

 

 

 

0 Likes
Message 11 of 17

Moshe-A
Mentor
Mentor

@kidznok hi,

 

does it work?

0 Likes
Message 12 of 17

kidznok
Advocate
Advocate

No, unfortunately no.
I created aitostart lisp to reset scale so when I open file it's running.
It's a second way for me.

0 Likes
Message 13 of 17

Moshe-A
Mentor
Mentor

i use r2022 and it works perfect for me and i am sure you are missing something.

0 Likes
Message 14 of 17

Moshe-A
Mentor
Mentor

maybe post your dwg and specify the scalelist names you want to delete

0 Likes
Message 15 of 17

kidznok
Advocate
Advocate

Hi, i would like to reset scale, just delete scales from xrefs in BricsCad.

0 Likes
Message 16 of 17

kidznok
Advocate
Advocate

It works when I use ctrl+S but not when I use button.
Save as not work too. Is it chance to add reset scale to _close? 
I will click X button then it reset scale, next close and ask to save.
I'm just wondering.

0 Likes
Message 17 of 17

Moshe-A
Mentor
Mentor

@kidznok  hi,

 

(if
(or
(= (car b) "QSAVE")
(= (car b) "SAVEAS")
(= (car b) "SAVE")
)


When you run this code to monitor these commands you can not expect AutoCAD to monitor other commands.

picking the X buttom should invokes the close command but on my experience long time ago it won't 😂

 

instead vlr-command-reactor you should move to:

vlr-dwg-reactor \ vlr-editor-reactor

 

using these events

vlr-beginClose \ vlr-beginSave  (as @Sea-Haven  recommended)

 

Moshe

 

 

 

0 Likes