Jump to content

Recommended Posts

Posted

Hi,

I want to set up some variables to combine a text with a variable portion to produce a new variable.

 

Ex:

 
(setq a 1500)
(setq b "CCC_DR" + a)
(setq c "CCC_Services" + a)

 

I will then use b and c to create a layer and alinetype with the combined names.

 

Thanks

Posted

Variables can only be of one type, i.e, STRing, INTeger, REAL, LIST etc.

 

You can test this type, using the "type" function (obviously...).. :P

 

So, if your variable "a" is an INTeger, you will need to convert it to a STRing before combining it with

 

"CCC_DR"

 

And you can then use "strcat" to concatenate the strings:

 

(setq b (strcat "CCC_DR" (itoa a)))

 

Hope this helps!

 

Lee

Posted

Thanks Lee,

 

That's great.

Posted

Lee,

I did get a bit stuck. I am trying to integrate it into my code. When I run this I am getting an error: "bad argument type: fixnump: nil". I have set d to be 1500 at the start as a default value so I'm not sure why I'm getting this. I think the COND is setup right since I set the value of d there based on the size.

 

 
(defun C:ESS02 () ;define function 
 (setq dcl_id (load_dialog "ESS.dcl")) ;load dialog
(setq d 1500)
;(setq b "CCC_SERVICES_EXISTING_Drainage_Storm_Sewer_1500")
 (if
   (not (new_dialog "ESS" dcl_id) ;test for dialog
   );not
   (progn
     (alert "Can not find your dcl file")
     (exit) ;exit if no dialog
   )
 );if
 (set_tile "1500" "1") ;Set radio_button T1 as default
 (setq hole "S1")   ;Set variable hole to S1 as default
 (action_tile "1500" "(setq hole \"S1\")") ;*store hole type
 (action_tile "1350" "(setq hole \"S2\")") ;*store hole type
 (action_tile "1200" "(setq hole \"S3\")") ;*store hole type
 (action_tile "1050" "(setq hole \"S4\")") ;*store hole type
 (action_tile "900" "(setq hole \"S5\")") ;*store hole type
 (action_tile "750" "(setq hole \"S6\")") ;*store hole type
 (action_tile "675" "(setq hole \"S7\")") ;*store hole type
 (action_tile "600" "(setq hole \"S8\")") ;*store hole type
 (action_tile "525" "(setq hole \"S9\")") ;*store hole type
 (action_tile "450" "(setq hole \"S10\")") ;*store hole type
 (action_tile "375" "(setq hole \"S11\")") ;*store hole type
 (action_tile "300" "(setq hole \"S12\")") ;*store hole type
 (action_tile "225" "(setq hole \"S13\")") ;*store hole type
 (action_tile "150" "(setq hole \"S14\")") ;*store hole type
 (action_tile "cancel" ;if cancel button pressed
  "(done_dialog)(setq userclick nil)" ;close dialog, set flag
 );action_tile
 (action_tile "accept" ;if O.K. pressed
  "(done_dialog)(setq userclick T))" 
 );action tile
 (start_dialog) ;start dialog
 (unload_dialog dcl_id) ;unload
 (if userclick                        ;When OK button is selected
   (cond                              ;And one of the following conditions apply
     ((= hole "S1")(setq d 1500))       ;If S1 selected, d = 1500
     ((= hole "S2")(setq d 1350))       ;If S2 selected, d = 1350
     ((= hole "S3")(setq d 1200))       ;If S3 selected, d = 1200
     ((= hole "S4")(setq d 1050))       ;If S4 selected, d = 1050
     ((= hole "S5")(setq d 900))       ;If S4 selected, d = 900
     ((= hole "S6")(setq d 750))       ;If S4 selected, d = 750
     ((= hole "S7")(setq d 675))       ;If S4 selected, d = 675
     ((= hole "S8")(setq d 600))       ;If S4 selected, d = 600
     ((= hole "S9")(setq d 525))       ;If S4 selected, d = 525
     ((= hole "S10")(setq d 450))      ;If S4 selected, d = 450
     ((= hole "S11")(setq d 375))      ;If S4 selected, d = 375
     ((= hole "S12")(setq d 300))      ;If S4 selected, d = 300
     ((= hole "S13")(setq d 225))      ;If S4 selected, d = 225
     ((= hole "S14")(setq d 150))      ;If S4 selected, d = 150
    ;(t (princ "\nNothing changed.")) ;_ end of optional else condition
   )                                  ;End cond
 )                                    ;End if
 (princ)                              ;Exit quietly
)                                      ;End defun
(princ "\nThis loaded fine")
(setq a (strcat "CCC_DR_" (itoa d)))
(setq b )strcat "CCC_SERVICES_EXISTING_Drainage_Storm_Sewer_" (itoa d)))
 (if (= (tblsearch "ltype" a) nil)  
      (command "-linetype" "l" a "acadiso.lin" "")
            (princ))
(graphscr)
(command "._-layer"   "N"   b   "M"   b   "L"   a  b   "C"   "84"   b   "LW"   "0.3"   b    "" )
(command "pline" pause "width" "0.0" "0.0" pause "width" "0.0" "0.0")
(princ)
)

Posted

There is quite a lot wrong with your code - you have parts of the code outside of the function definition, and your parentheses aren't right.

 

I have re-written your code and made a few comments, this isn't tested, but take note of the way I have altered it.

 

(defun C:ESS02  (/ dcl_id d hole userclick a b)
 ;; Make sure that you localise your variables!

 (cond
   ((minusp (setq dcl_id (load_dialog "ESS.dcl")))
    (princ "\n<< DCL File not Found >>"))
   ((not (new_dialog "ESS" dcl_id))
    (princ "\n<< Dialog could not be Loaded >>"))
   (t
     (setq d 1500 hole "S1")
     (set_tile "1500" "1")  ;Set radio_button T1 as default
     (action_tile "1500" "(setq hole \"S1\")") 
     (action_tile "1350" "(setq hole \"S2\")")
     (action_tile "1200" "(setq hole \"S3\")")
     (action_tile "1050" "(setq hole \"S4\")") 
     (action_tile "900"  "(setq hole \"S5\")")
     (action_tile "750"  "(setq hole \"S6\")") 
     (action_tile "675"  "(setq hole \"S7\")")
     (action_tile "600"  "(setq hole \"S8\")")
     (action_tile "525"  "(setq hole \"S9\")")
     (action_tile "450"  "(setq hole \"S10\")") 
     (action_tile "375"  "(setq hole \"S11\")")
     (action_tile "300"  "(setq hole \"S12\")") 
     (action_tile "225"  "(setq hole \"S13\")") 
     (action_tile "150"  "(setq hole \"S14\")") 
     (action_tile "cancel" "(done_dialog)") ; Userclick will be nil anyway
     (action_tile "accept" "(done_dialog)(setq userclick T))")

    (start_dialog) ;start dialog
    (unload_dialog dcl_id) ;unload

    (if userclick ;When OK button is selected
      (progn
        (setq d
          (cond ;And one of the following conditions apply
            ((= hole "S1") 1500) 
            ((= hole "S2") 1350) 
            ((= hole "S3") 1200)
            ((= hole "S4") 1050) 
            ((= hole "S5")  900)
            ((= hole "S6")  750) 
            ((= hole "S7")  675) 
            ((= hole "S8")  600)
            ((= hole "S9")  525) 
            ((= hole "S10") 450) 
            ((= hole "S11") 375)
            ((= hole "S12") 300) 
            ((= hole "S13") 225) 
            ((= hole "S14") 150)))

        (setq a (strcat "CCC_DR_" (itoa d))
              b (strcat "CCC_SERVICES_EXISTING_Drainage_Storm_Sewer_" (itoa d)))
        (if (not (tblsearch "LTYPE" a))
          (command "_.-linetype" "_l" a "acadiso.lin" ""))
        (command "._-layer"   "_N"   b   "_M"   b   "_L"   a  b   "_C"   "84"   b   "_LW"   "0.3"   b    "" )
        (command "pline" pause "width" "0.0" "0.0" pause "width" "0.0" "0.0")))))
 (princ))

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