Set QNewTemplate If Statement

Set QNewTemplate If Statement

ArchD
Collaborator Collaborator
922 Views
3 Replies
Message 1 of 4

Set QNewTemplate If Statement

ArchD
Collaborator
Collaborator

I'm looking to check if the variable "qnewtemplate" is set to a standard template but it gives me an error: ; error: bad argument type: stringp nil

 

I can't figure it out and I know it's a simple solution. If anyone can help, I'd really appreciate it.

 

(setq cphQNewTemplate "\\\\cph\\offices\\CADD\\AutoCAD Resources\\_Support-Civil and Landscape\\_Templates\\_cph - (STB) Standard Template (vR21).dwt")

(if 
	(not
		(wcmatch
			(getenv "qnewtemplate")
			cphQNewTemplate
		)
	)
	(setenv "qnewtemplate" cphQNewTemplate)
)
Archie Dodge
Applications Expert - Infrastructure Solutions Division
IMAGINiT Technologies
0 Likes
Accepted solutions (2)
923 Views
3 Replies
Replies (3)
Message 2 of 4

_gile
Consultant
Consultant
Accepted solution

Hi,

 

You should first check if (getenv "qnewtemplate") is not nil.

 

(if
  (or (null (getenv "qnewtemplate"))
      (not
        (wcmatch
          (getenv "qnewtemplate")
          cphQNewTemplate
        )
      )
  )
   (setenv "qnewtemplate" cphQNewTemplate)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

Am I missing something?  If you're going to set it to a new value if it doesn't already match it, it's going to end up with that value in any case, so you may as well just set it that way, without bothering to check whether it matches, or even whether it exists already.  This part alone:

 

(setenv "qnewtemplate" cphQNewTemplate)

 

would seem to accomplish what you're after, with the same end result as the longer code, regardless of initial conditions.

Kent Cooper, AIA
Message 4 of 4

ArchD
Collaborator
Collaborator

You are not missing anything. You are absolutely correct. I am a dodo.

 

I had to use the If Not statement on another part and was in that mode thinking I needed to check everything.

 

Thanks, I'm off to get some coffee now and think of the weekend.

Archie Dodge
Applications Expert - Infrastructure Solutions Division
IMAGINiT Technologies
0 Likes