Error when creating annotation scale

Error when creating annotation scale

Browning_Zed
Advocate Advocate
615 Views
6 Replies
Message 1 of 7

Error when creating annotation scale

Browning_Zed
Advocate
Advocate

Good afternoon, forum members.
I am trying to create a scale using the following function:

 (defun CreateScale  ( nme dun lun / dictname )
	(setq dictname (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_SCALELIST"))))
	(dictadd dictname
		(entmakex
			(list
				'(0 . "SCALE")
				(cons 330 dictname)
				'(100 . "AcDbScale")
				'(70 . 0)
				(cons 300 nme)
				(cons 140 dun)
				(cons 141 lun)
				'(290 . 0)
			)
		)
	)
)

Run the function:

(CreateScale "1:20" 50 1)


And this returns an error: too few arguments. What could be the reason?

0 Likes
Accepted solutions (1)
616 Views
6 Replies
Replies (6)
Message 2 of 7

hak_vz
Advisor
Advisor

Why no simple as this. This will create new annotation scale if its not already present

(defun CreateScale  (scalestr / scalelist *error*)
 (defun *error* () (setvar 'cmdecho 1) princ)
	(setq scalelist 
		(vl-remove nil
			   (mapcar
				 (function
				   (lambda (x)
					 (if (eq (car x) 350)
					   (cdr (assoc 300 (entget (cdr x))))
					 )
				   )
				 )
				 (dictsearch (namedobjdict) "ACAD_SCALELIST")
			   )
		)
	)
	(setvar 'cmdecho 0)
	(cond
		((not (member scalestr scalelist))
			(command "-scalelistedit" "Add" scalestr scalestr "e")
		)
		(T (princ (strcat "\n Scale " scalestr " already exist!")))
	)
	(setvar 'cmdecho 1)
	(princ)
)
Usage :  (CreateScale "1:60")

 

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.
Message 3 of 7

Browning_Zed
Advocate
Advocate

Thanks, it works, but I would like to be able to specify drawing units and paper units myself when creating a scale. That is, in the function, I need three arguments: scale name, drawing units, paper units.

0 Likes
Message 4 of 7

hak_vz
Advisor
Advisor

@Browning_Zed wrote:

Thanks, it works, but I would like to be able to specify drawing units and paper units myself when creating a scale. That is, in the function, I need three arguments: scale name, drawing units, paper units.


String is formulated "paper_units : drawing units" and this is also name of the scale

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 5 of 7

Browning_Zed
Advocate
Advocate

Yes, but I need the name to be different from units, options like this:
name: "1:20" | drawing units: 50 | paper units: 1

0 Likes
Message 6 of 7

hak_vz
Advisor
Advisor
Accepted solution

Ok then as simple as this

 

(defun CreateScale  (name paperunits drawingunits /  *error*)
	(defun *error* () (setvar 'cmdecho 1) princ)
	(setvar 'cmdecho 0)
	(command "-scalelistedit" "Add" name (strcat paperunits ":" drawingunits) "e")
	(setvar 'cmdecho 1)
	(princ)
)
Usage: 

(CreateScale "whatever" paper_units drawing_units)
(CreateScale "whatever" "50" "1")

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

Browning_Zed
Advocate
Advocate

Thanks a lot for your help, hak_vz.