AutoCAD Plant 3D Forum
Welcome to Autodesk’s AutoCAD Plant 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Plant 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp to Select All Plant3D objects in drawing

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Jonathan.CharltonE35Y2
408 Views, 6 Replies

Lisp to Select All Plant3D objects in drawing

Hello!

I'm currently using Plant 3D 2022.1.2 (P3D_S051.1521), built on S.173.0.0 AutoCAD 2022.1.3.

All relevant updates have been installed.

I'm currently trying to write a simple lisp function that will allow me to select all Plant 3D objects within modelspace.
I've got what seems to be the correct code to do so, but whenever I run the code it fails to select the items in question.

I've tried (2) different methods and from what I've seen online, both should work but neither do.

"V1"
(defun c:SAD

(ssget "X" '((0 . "ACPP")))

(command "select" "p" "")

)
----------------------------------------
"V2"
(defun c:SAD

(ssget "X" '((0 . "ACPP")))

(setq ss1 (ssget "P"))

)

 

I've also been getting a consistent error when loading the code into P3D, which states ; error: syntax error
This code was written and formatted in Visual Studio Code, UTF-8 Encoding. 
I've tried re-encoding the file into ANSI in Wordpad++,  windows1252, iso88591, iso88593, and iso885915 in Vsc, but none of them seem to fix this.

Can anyone lend me a hand in determining why the above code isn't performing as intended, and why I continue to have the syntax error?

Much appreciated.

Labels (1)
6 REPLIES 6
Message 2 of 7

Hello, I looks like your missing the asterisk * in your search. It should be:

 

 

(ssget "x" '((0 . "ACPP*")))

 

 

 
 
 
If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"
Message 3 of 7

@matt.worland,

Thank you for your reply!
In the time since I posted this, I did notice some errors with what I had written.
here is the current code:

(defun c:sad ()
(setq ss1 (ssget "X" '((0 . "ACPP*"))))
(setq ss2 (ssget "P"))
)

Now the code does create a new selection set and names it, but the 3rd line doesn't seem to be running as intended.
It refuses to set the previous selection set as active.
Any ideas?

Message 4 of 7
matt.worland
in reply to: matt.worland

I believe the syntax error could be the missing parens after your defun

(defun c:SAD ()
If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"
Message 5 of 7

Got it, that's been added.
Am I missing something that's keeping the lisp from running the 3rd line to select the previous selection set?
Or do I have the code structured incorrectly that you can tell?

Message 6 of 7

SSGET allows you to store a colleciton of entities in a variable. It won't select them visually on the screen, but it will allow you to iterate through them.

Once you have your collection you can use a vlax-for, like this

 

(setq ss1(ssget "X" '((0 . "ACPP*"))))
(vlax-for objCurrent (setq sel (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
  ;Do your stuff here
  ; you could even highlight them here
  (vla-Highlight objCurrent :vlax-True)
)

 

If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"
Message 7 of 7

This is exactly what I was looking for, and resolves the issue.
Thank you so much for your input and time!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report