AutoCAD PID component coding automation with LSP and DCL

wouter_klootwijk
Explorer

AutoCAD PID component coding automation with LSP and DCL

wouter_klootwijk
Explorer
Explorer

Hello. I normally don't post on forums, but I'm so stuck in this problem that I see no other option.

 

I'm working on a LISP code that allows me to easily generate the coding of a PID component. Once the user enters the command "ETP_PID", a pop-up window appears. In the first column, the user can choose a component, for example, "ball valve". Additionally, there are three more columns where the user can select various options. After the user clicks "ok", Autocad searches for the dynamic block associated with the name selected in list 1. This block contains an attribute named "Code". I want to merge the previously selected values from lists 1, 2, 3, and 4, and have them filled in my attribute "code".

 

Any ideas?

0 Likes
Reply
Accepted solutions (2)
613 Views
4 Replies
Replies (4)

komondormrex
Mentor
Mentor
Accepted solution

hi,

check the following. only inserting is corrected.

(defun C:ETP_PID ();/ WHAT_NEXT LIJST1 LIJST2 LIJST3 LIJST4 dcl_ID LST1 LST2 LST3 LST4 ETP_PID_LST3)

  (setq dcl_id (load_dialog "BPID7.dcl"))

  (if (not (new_dialog "samp1" dcl_id))
      (exit))

  (setq LIJST1 '( "211" "221" "231" "241" "251" "261" "311" "321" "331" "341" "351" "361" "411" "421" "431" "511" "521" "531" "541" "551" "561" "571" "581" "911" "912" "921" "922" "930" "931" "932" "940" "941" "942")
        LIJST2 '( "CV" "GW" "AF" "BW" "VL")
        LIJST3 '( "TT" "XT" "TS" "PT" "PS" "FT" "FS" "LT" "LS" "WM" "EM" "VE" "FM" "BP" "CP" "RK" "VK" "DK" "IK" "TK" "Kogelkraan" "DP" "PK" "GD" "OG" "MF" "DB")
        LIJST4 '( "Aanvoer" "Retour")
  )

  (if (not LST1)(setq LST1 "0"))
  (if (not LST2)(setq LST2 "0"))
  (if (not LST3)(setq LST3 "0"))
  (if (not LST4)(setq LST4 "0"))

  (start_list "LIJST1")
  (mapcar 'add_list LIJST1)
  (end_list)

  (start_list "LIJST2")
  (mapcar 'add_list LIJST2)
  (end_list)

  (start_list "LIJST3")
  (mapcar 'add_list LIJST3)
  (end_list)

  (start_list "LIJST4")
  (mapcar 'add_list LIJST4)
  (end_list)

  (set_tile "LIJST1" LST1)
  (set_tile "LIJST2" LST2)
  (set_tile "LIJST3" LST3)
  (set_tile "LIJST4" LST4)

  
  (action_tile "LIJST1"
  "(setq LST1 $value)
   (setq VariabeleA (nth (atoi LST1) LIJST1))")
  
  (action_tile "LIJST2"
  "(setq LST2 $value)
   (setq VariabeleB (nth (atoi LST2) LIJST2))")
  
  (action_tile "LIJST3"
  "(setq LST3 $value)
   (setq VariabeleC (nth (atoi LST3) LIJST3))
   (setq ETP_PID_LST3 (strcat \"ETP-PID-\" VariabeleC))") 

  (action_tile "LIJST4"
  "(setq LST4 $value)
   (setq VariabeleD (nth (atoi LST4) LIJST4))")

  
  (action_tile
    "cancel"
    "(done_dialog)"
  )

  (action_tile
    "accept"
    "(done_dialog)"
  )

  (start_dialog)

  (unload_dialog dcl_id)

  ; Check of ETP_PID_LST3 is ingesteld en voer de blokinvoeging uit als dat zo is
  (if (and ETP_PID_LST3 (not (equal ETP_PID_LST3 "0")))
      (progn
	(vla-insertblock (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
		 		 (vlax-3d-point (getpoint "\Pick point to insert block: "))
		 		 (strcat "ETP-PID-" (nth (atoi LST3) LIJST3)) 
		 		 1 1 1 0
	)
	(setpropertyvalue (entlast) "Code" (strcat (nth (atoi LST1) LIJST1) "-" (nth (atoi LST2) LIJST2) "-" (nth (atoi LST3) LIJST3) "-" (nth (atoi LST4) LIJST4))) 
        (princ "\nBlock inserted.")
      )
  )
  (princ)
)

 

0 Likes

wouter_klootwijk
Explorer
Explorer

@komondormrex Thank you for your reply!

 

When I use your suggested code, I can select a point, but the block does not insert.

 

I see the following in the command line:

       Command: ETP_PID
       Pick point to insert block: ; error: Automation Error. File error
       Command:

0 Likes

komondormrex
Mentor
Mentor
Accepted solution

says that there is no definition of block 

 (strcat "ETP-PID-" (nth (atoi LST3) LIJST3))

in the drawing. if so, you need firstly to find where the said block file is and then insert it from the path found. 

0 Likes

wouter_klootwijk
Explorer
Explorer

@komondormrex Thanks! The code is working now!

0 Likes