How to Insert Equipment via Command Line (LISP) Without Dialog Box – Like Block Insertion?

How to Insert Equipment via Command Line (LISP) Without Dialog Box – Like Block Insertion?

ehemmati
Explorer Explorer
383 Views
10 Replies
Message 1 of 11

How to Insert Equipment via Command Line (LISP) Without Dialog Box – Like Block Insertion?

ehemmati
Explorer
Explorer

Hi everyone,

I'm looking to insert multiple pre-saved equipment definitions in AutoCAD Plant 3D  without using the equipment dialog box.

My goal:

Use a LISP routine to insert a specific equipment type (already saved in the tool palette or catalog)

Control the whole process via command line, similar to using -INSERT for blocks

Pull insertion data (location, count, orientation, etc.) from an Excel sheet (which I can process with LISP or import separately)

I’m trying to automate placement for ~40–50 units and keep everything scriptable. Any ideas, sample code, or direction would be really appreciated!

Thanks in advance!

0 Likes
384 Views
10 Replies
Replies (10)
Message 2 of 11

Moshe-A
Mentor
Mentor

@ehemmati ,

 

When you say i can process from excel the insertion point, scale, rotation - show us what you have?

post sample dwg containing a few blocks + an excel data file.

 

Moshe 

0 Likes
Message 3 of 11

Sea-Haven
Mentor
Mentor

Providing Plant 3d supports get-application for Excel then you can read a Excel directly, choose a range or a do all. Do you have a program for the Excel part ?

0 Likes
Message 4 of 11

ehemmati
Explorer
Explorer

for example in the attached screen shot , you will see many electrical terminal blocks which I already defined each as an equipment ( to be considered in BOM and also weight of total skid). by now I manually insert those equipment one by one. i already developed a lisp code to insert them all based on an excel table which is a sample attached. the routine is also attached but this routine works for blocks not for plant 3d equipment. i am looking for a way to control the create equipment in plant 3d not with dialogue menu but with command line so that be able to create a similar code to insert equipment in dwg.

 

 

sample code for autocad blocks


(defun c:e3 ()
(command "undo" "begin")
(setq add (getvar "dwgprefix"))
(setq file (getfiled " Select Import File : " add "csv" 0))
(setq fil (open file "r"))
(setq po0 (getpoint " Basepoint "))
(setq x0 (car po0))
(setq y0 (cadr po0))
(setq Z0 (caddr po0))

(setq li nil)


(setq dinx 0)
(setq diny -2.0313)
(setq dinz -0.8891)
; (command "insert" "DIN16" "_non" po0 1 1 0)

(setq f 0)
(while (and (setq txt (read-line fil)) (/= txt ""))
(setq n (strlen txt))
(setq d1 "")
(setq d2 "")
(setq i 0)
(setq j 1)
(setq xxx 0)
(repeat n
(setq i (1+ i))
(setq let (substr txt i 1))
(if (/= let ",")
(cond
((= j 1) (setq d1 (strcat d1 let)))
((= j 2) (setq d2 (strcat d2 let)))
)
(setq j (1+ j))
)
)
(setq f (1+ f))


(if (OR (= D2 "DIN16") (= D2 "din16"))
(setq li (append li (list (list "DIN16" d1 "0" "2.0313" "0.8891" f "0.25") ))))
(if (OR (= D2 "DIN14") (= D2 "din14"))
(setq li (append li (list (list "DIN14" d1 "0" "2.0313" "0.8891" f "0.25") ))))

(if (OR (= D2 "D") (= D2 "d"))
(setq li (append li (list (list "WDU25" d1 "0.0.3150" "-0.0848" "-0.0770" f "0.2008") ))))

(if (OR (= D2 "DG") (= D2 "dg")) (setq li (append li (list (list "WPE25" d1 "0.0.3150" "-0.0848" "-0.0769" f "0.2008" )))))
(if (OR (= D2 "A") (= D2 "a"))
(setq li (append li (list (list "WDU40" d1 "0.0.3150" "0.0487" "-0.0922" f "0.2402" ) ) )))
(if (OR (= D2 "AG") (= D2 "ag"))
(setq li (append li (list (list "WPE40" d1 "0.0.3150" "0.0021" "0.0001" f "0.2402" )))))
(if (OR (= D2 "B") (= D2 "b") (= D2 ""))
(setq li (append li (list (list "WAP" d1 "-0.0971" "-0.2567" "0.2591" f "0.0591" )))))
(if (OR (= D2 "E") (= D2 "e"))
(setq li (append li (list (list "WEW" d1 "0" "0" "0" f "0.3150")))))
(if (OR (= D2 "P") (= D2 "p"))
(setq li (append li (list (list "P" d1 "0.0.1148" "-3.2501" "-1.7735" f "1.3386")))))
(if (OR (= D2 "PLC") (= D2 "plc"))
(setq li (append li (list (list "PLC" d1 "0.0.3150" "1.7443" "0.9155" f "3.9370")))))
(if (OR (= D2 "F") (= D2 "f"))
(setq li (append li (list (list "FUSEHOLDER" d1 "0.3445" "0.7411" "0.7229" f "0.6890")))))
(if (OR (= D2 "N") (= D2 "n"))
(setq li (append li (list (list "NETWORKSWITCH" d1 "0" "0.5668" "-2.3591" f "4.5")))))

(if (OR (= D2 "R") (= D2 "r"))
(setq li (append li (list (list "RELAY" d1 "0" "1.7443" "-0.6485" f "1.5")))))

(if (OR (= D2 "FCM6AC") (= D2 "fcm6ac"))
(setq li (append li (list (list "FCM6ACIN" d1 "0" "1.7443" "-0.2599" f "0.5645")))))
(if (OR (= D2 "FCMANALOG") (= D2 "fcmanalog"))
(setq li (append li (list (list "FCMANALOG" d1 "0" "1.7443" "-0.2599" f "1.1613")))))
(if (OR (= D2 "PS2") (= D2 "ps2"))
(setq li (append li (list (list "POWERSUPPLY2" d1 "0" "-2.7814" "-1.8699" f "2.6772")))))
(if (OR (= D2 "WDK") (= D2 "wdk"))
(setq li (append li (list (list "WDK25" d1 "0" "1.7443" "0.9155" f "0.2008")))))
(if (OR (= D2 "WDKG") (= D2 "wdkg"))
(setq li (append li (list (list "WDK25G" d1 "0" "1.7347" "0.8891" f "0.2008")))))

(if (OR (= D2 "WDKB") (= D2 "wdkb"))
(setq li (append li (list (list "WDKB25" d1 "0" "1.7192" "0.8695" f "0.0591")))))

(if (OR (= D2 "ATF") (= D2 "atf"))
(setq li (append li (list (list "ATF" d1 "0" "1.7443" "0.9155" f "0.9252")))))
(if (OR (= D2 "F2") (= D2 "f2"))
(setq li (append li (list (list "FUSEHOLDER2" d1 "0" "1.7443" "0.9155" f "0.3110")))))

(setq xt x0)
(setq y y0)
(setq Z Z0)
(setq gg 1)
)
(foreach a li
(setq bn (car a))
(setq num (nth 1 a))

(setq dx (atof (nth 2 a)))
(setq dy (atof (nth 3 a)))
(setq dZ (atof (nth 4 a)))
(setq f (nth 5 a))
(setq w (atof (nth 6 a)))
(setq ang 0)
(if (= 3 (strlen num))
(setq ang 90)
)
(setq po1 (list xt y Z))


(setq po2 (list (+ xt dX dinx) (+ dy y diny) (+ dz z dinz)))
(setq xt (+ xt W))

(command "insert" bn "_non" po2 1 1 0)

(princ)
)
(close fil)
(command "undo" "end")
)

 

0 Likes
Message 5 of 11

Moshe-A
Mentor
Mentor

@ehemmati hi,

 

I see your are writing AutoLISP and would like to give you some guidelines:-

   i see your csv file contains only block names, from are you getting the insertion base point x/y factors 

1. when a data file is involve, best practice first is to read all data records into autolisp memory (into a big list) than process it.

   

2. calling insert command as (command "-insert") will skip the std insert dialog box. if a block has attributes be aware of attdia & attreq sysvars

 

does this help you, or you need more?

 

Moshe

 

0 Likes
Message 6 of 11

ehemmati
Explorer
Explorer

please forget about my current lisp. my problem now is how to create equipment in plant 3d with command line. for blocks, i am ok but i am looking for some solution for equipment.

0 Likes
Message 7 of 11

Moshe-A
Mentor
Mentor

i do not have plant3d but have you tried what i said on 2?

 

 

0 Likes
Message 8 of 11

ehemmati
Explorer
Explorer

YES BUT WHEN USING PLANTEQUIPMENTCREATE WHITH - OR _ AGAIN THE DIALOG APPERS.

0 Likes
Message 9 of 11

DVaquand
Advisor
Advisor

Hello @ehemmati 

 

I have put on my site an example and a principle of insertion, by AutoLISP programming, of block equipment.
Maybe this will help you and give you ideas.
The information is in French but easily understandable.

Here is the link: https://dovaq.fr/applications/
Search "Convertir des blocs AutoCAD en équipements divers Plant 3D"


Video https://screencast.autodesk.com/Embed/Timeline/f9b84eab-3dee-4668-a4fb-42550277595d

 

== French ==

 

J'ai mis sur mon site un exemple et un principe d'insertion, par programmation AutoLISP, des équipements blocs.
Peut-être cela pourra vous aider et vous donner des idées.
L'info est en français mais facilement compréhensible.

Voici le lien : https://dovaq.fr/applications/
Rechercher "Convertir des blocs AutoCAD en équipements divers Plant 3D"

 

https://screencast.autodesk.com/Embed/Timeline/f9b84eab-3dee-4668-a4fb-42550277595d

 

Cordialement
Dominique VAQUAND
www.dovaq.fr

Cette publication vous a-t-elle été utile ? N’hésitez pas à attribuer la mention J’aime à cette publication.
Avez-vous obtenu la réponse à votre question ? Cliquez ensuite sur le bouton ACCEPTER LA SOLUTION.

EESignature

0 Likes
Message 10 of 11

ehemmati
Explorer
Explorer

Thank you @DVaquand,

I found your solution very helpful. Based on that, I’m planning to change my approach: I’ll first insert blocks using LISP, and then immediately convert those blocks into Plant 3D equipment.

Now I have a follow-up question:

Is there a way to assign equipment properties (such as Manufacturer, Weight, Item Code, or Description) to the last converted equipment, using either LISP or command-line methods?

I’d like to automate that step too, so that each equipment item not only gets inserted but also has its properties filled out from an Excel sheet — without needing to open the Properties palette or Data Manager manually.

Thanks again for your time and support!

0 Likes
Message 11 of 11

jabowabo
Mentor
Mentor

Another approach would be to create your equipment in a separate library project, convert it to a block, then insert it from there with the explode on insert option.  You will not be able to modify any Plant 3D properties automatically via LISP - only via the .NET API.

0 Likes