Jump to content

Recommended Posts

Posted

Hi all

 

I've got a text routine that works as I want it. It checks the cannoscalevalue and sets the text size accordingly.

 

;;Type T1 to start the MTEXT command on the correct layer 

(command "-dimstyle" "R" "Standard")

(defun c:T1 ()
 (setvar "cmdecho" 0)
   
 (setvar "dimscale" (/ 1.0 (getvar "CANNOSCALEVALUE")))

(setq ins (getvar "insunits"))
   
(cond
(= (getvar 'dimscale) 1)
(= (getvar 'dimscale) 2)
(= (getvar 'dimscale) 5)	
(= (getvar 'dimscale) 10)
(= (getvar 'dimscale) 20)
(= (getvar 'dimscale) 25)
(= (getvar 'dimscale) 50)
(= (getvar 'dimscale) 100)
(= (getvar 'dimscale) 200)
(= (getvar 'dimscale) 250)
(= (getvar 'dimscale) 500)
(= (getvar 'dimscale) 1000)
(= (getvar 'dimscale) 2000)
(= (getvar 'dimscale) 2500)
(= (getvar 'dimscale) 5000)
(= (getvar 'dimscale) 10000)
)	

(setq scale (getvar "DIMSCALE"))
(setq ln (strcat "L-TEXT-SMLL-"(rtos scale 2 0)))
(command "-LAYER" "m" ln "co" "7" ln "p" "p" ln "")

(setvar "CECOLOR" "bylayer")

	(prompt "\n Please pick your start point for DTEXT ")
   
	(setvar "TEXTSTYLE" "Standard") 
	(setvar "TEXTSIZE" (* 1.8(getvar "DIMSCALE")))
	
	(initdia)(command "mtext" pause)
 (setvar "cmdecho" 1)
(princ)
)

 

Now I want to add some code to check whether the drawing is in units of mm or metres and apply a scaling to account for that. Below are my additions in red

 

;;Type T1 to start the MTEXT command on the correct layer 

(command "-dimstyle" "R" "Standard")

(defun c:T1 ()
 (setvar "cmdecho" 0)
   
[color="red"](setq ins (getvar "insunits"))[/color]
   
(cond
[color="red"]((= ins 4)[/color]
[color="red"](setvar "dimscale" (/ 1.0 (getvar "CANNOSCALEVALUE")))[/color]

[color="red"]((= ins 6)[/color]
[color="red"](setvar "dimscale" (/ 0.001 (getvar "CANNOSCALEVALUE")))[/color]

(= (getvar 'dimscale) 1)
(= (getvar 'dimscale) 2)
(= (getvar 'dimscale) 5)	
(= (getvar 'dimscale) 10)
(= (getvar 'dimscale) 20)
(= (getvar 'dimscale) 25)
(= (getvar 'dimscale) 50)
(= (getvar 'dimscale) 100)
(= (getvar 'dimscale) 200)
(= (getvar 'dimscale) 250)
(= (getvar 'dimscale) 500)
(= (getvar 'dimscale) 1000)
(= (getvar 'dimscale) 2000)
(= (getvar 'dimscale) 2500)
(= (getvar 'dimscale) 5000)
(= (getvar 'dimscale) 10000)
)	

(setq scale (getvar "DIMSCALE"))
(setq ln (strcat "L-TEXT-SMLL-"(rtos scale 2 0)))
(command "-LAYER" "m" ln "co" "7" ln "p" "p" ln "")

(setvar "CECOLOR" "bylayer")

	(prompt "\n Please pick your start point for DTEXT ")
   
	(setvar "TEXTSTYLE" "Standard") 
	(setvar "TEXTSIZE" (* 1.8(getvar "DIMSCALE")))
	
	(initdia)(command "mtext" pause)
 (setvar "cmdecho" 1)
(princ)
)

 

But I get an error: malformed list on input

 

I don't really have an understanding of the COND statement and assume I've not got the syntax correct. Can anyone suggest any help?

 

Thanks

Paul

Posted

(cond
(= (getvar 'dimscale) 1)
(= (getvar 'dimscale) 2)
(= (getvar 'dimscale) 5)	
(= (getvar 'dimscale) 10)
(= (getvar 'dimscale) 20)
(= (getvar 'dimscale) 25)
(= (getvar 'dimscale) 50)
(= (getvar 'dimscale) 100)
(= (getvar 'dimscale) 200)
(= (getvar 'dimscale) 250)
(= (getvar 'dimscale) 500)
(= (getvar 'dimscale) 1000)
(= (getvar 'dimscale) 2000)
(= (getvar 'dimscale) 2500)
(= (getvar 'dimscale) 5000)
(= (getvar 'dimscale) 10000)
)	

 

Hi Paul,

 

What is the use of value passed to cond function in your routine?

 

Regardless of what you codes do, you have two brackets missing as I highlighted them in the following correction:

(cond
((= (setq ins (getvar "insunits")) 4)(setvar "dimscale" (/ 1.0 (getvar "CANNOSCALEVALUE")))[color="red"])[/color]
((= ins 6) (setvar "dimscale" (/ 0.001 (getvar "CANNOSCALEVALUE")))[color="red"])[/color]
)

Posted

Thanks for responding Tharwat.

 

What is the use of value passed to cond function in your routine?

 

Good question. I've tried it without this code and it still works. This is a legacy code and I think it was to force the routine to run only on the company default scales.

 

Regardless of what you codes do, you have two brackets missing as I highlighted them in the following correction:

(cond
((= (setq ins (getvar "insunits")) [color="red"][b]4)[/b][/color](setvar "dimscale" (/ 1.0 (getvar "CANNOSCALEVALUE")))[color="red"])[/color]
((= ins 6) (setvar "dimscale" (/ 0.001 (getvar "CANNOSCALEVALUE")))[color="red"])[/color]
)

 

Thanks - works perfectly. Can you explain please why the code doesn't need to be

((= ins 4)

like it is for

((= ins 6)

Posted
Thanks for responding Tharwat.

You are welcome.

 

Thanks - works perfectly. Can you explain please why the code doesn't need to be

((= ins 4)

like it is for

((= ins 6)

 

No difference at all, I just moved the expression that gets the System Variable "insunits" into the first expression in cond function to avoid the re-use of the variable assigned to it which is 'ins' two times and to reduce the quantity of lines in the program and all of that is the same as you did in your example.

 

You can move it back outside of cond function if you would like to, no harm would take a place.

Posted
No difference at all, I just moved the expression that gets the System Variable "insunits" into the first expression in cond function to avoid the re-use of the variable assigned to it which is 'ins' two times and to reduce the quantity of lines in the program and all of that is the same as you did in your example.

 

You can move it back outside of cond function if you would like to, no harm would take a place.

 

Thanks Tharwat. I understand - it's a more efficient use of the code. Thanks again for your help with this.

Posted
Thanks Tharwat. I understand - it's a more efficient use of the code. Thanks again for your help with this.

 

Exactly, and you are welcome.

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