Jump to content

Conditional Lisp call to insert data based on user input


ishka

Recommended Posts

Am I missing something here? I have an original code that I would want to make it user choice based, but it seems it does not work as intended when conditions are used.

So original code is as:

 

(defun c:esd_gcid ( / GRDREF MAPPATH)

(setvar "cmdecho" 1)

(setvar "filedia" 0)

(setvar "cmddia" 0)

(command "layer" "M" "G-NPLT" "")

(command "rectang" PAUSE PAUSE)

(princ "\nCAD Data...")

(setq GRDREF (getstring "Enter Data Type: "))

(setq MAPPATH (strcat "M:\\GIS-CAD\\Cadastre\\TCAD\\DWG\\TCAD" GRDREF))

(command "adedrawings" "AT" MAPPATH "X")

(command "adequery" "C" "D" "L" "L" "P" "C" PAUSE "X" "E" "D")

(command "adedrawings" "DE" "*" "X")

(setvar "cmddia" 1)

(setvar "filedia" 1)

(princ)

)

 

The modified conditional code is

 

(defun c:esd_gcid ( / GRDREF MAPPATH)

(setvar "cmdecho" 1)

(setvar "filedia" 0)

(setvar "cmddia" 0)

(command "layer" "M" "G-NPLT" "")

(command "rectang" PAUSE PAUSE)

(princ "\nCAD Data...")

(setq GRDREF (getstring "Enter Data Type: "))

(cond

( (= GRDDEF "TCAD") (setq MAPPATH (strcat "M:\\GIS-CAD\\Cadastre\\TCAD\\DWG\\" GRDREF)))

( (= GRDDEF "TCAD-TEXT") (setq MAPPATH (strcat "M:\\GIS-CAD\\Cadastre\\TCAD\\DWG\\" GRDREF)))

)

(command "adedrawings" "AT" MAPPATH "X")

(command "adequery" "C" "D" "L" "L" "P" "C" PAUSE "X" "E" "D")

(command "adedrawings" "DE" "*" "X")

(setvar "cmddia" 1)

(setvar "filedia" 1)

(princ)

)

 

What am I losing in the process? Is the GRDREF not stored anywhere before it is passed to the condition? What I try to achieve is based on the user answer to load specific data using the mapattach. I don't want to make individual lisp commands for each type of data.

Link to comment
Share on other sites

You are assigning the return of getstring to a variable GRD[highlight]R[/highlight]EF but testing the value of GRD[highlight]D[/highlight]EF.

 

However, the conditional is redundant since you appear to be concatenating the same path, whatever the value of GRDREF.

Link to comment
Share on other sites

You are assigning the return of getstring to a variable GRD[highlight]R[/highlight]EF but testing the value of GRD[highlight]D[/highlight]EF.

 

However, the conditional is redundant since you appear to be concatenating the same path, whatever the value of GRDREF.

 

I see. I guess it was my user error then there. The GRDDEF should have been the GRDREF. That was my intention, but I guess fat fingers do good job of messing. Thanks for pointing out my error on coding. This was actually my first ever attempt at writing a lisp routine. So I am on the right track. Thanks a lot Lee. Your posts and replies are always on target :)

Link to comment
Share on other sites

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