Help with AutoLISP to Add/Remove Bolts in connection within joint box in Advance Steel

Help with AutoLISP to Add/Remove Bolts in connection within joint box in Advance Steel

boxoniy727
Explorer Explorer
266 Views
2 Replies
Message 1 of 3

Help with AutoLISP to Add/Remove Bolts in connection within joint box in Advance Steel

boxoniy727
Explorer
Explorer

Hello everyone,

 

I'm working on an AutoLISP code for Advance Steel. My goal is to create a script that allows me to select a bolt within a that is locked in a joint box and add/remove him from connection with eg. plate or beam. Since its in a jointbox it can't be manipulated by using available commands. . 

 

What I Want:

 

1. Select a bolt (from various types like ASTBOLTMID, ASTBOLTCORNER, etc.).

2. Prompt the user to either add or remove objects (plate or beam) from this bolt connection.

3. If the user chooses to add, they should be able to select objects (like ASTPLATE or ASTBEAM) to add to the bolt connection.

4. If the user chooses to remove, they should be able to select objects to remove from the bolt connection.

 

 

 

The Problem:

 

The Code I Have:

 

(defun c:AddBoltToConnection (/ ss ee userChoice connectionObj boltHandle objectHandles)

 

  (vl-load-com) ;; Ensure the Visual LISP environment is loaded

 

  

 

  ;; Select a bolt

 

  (setq ss (ssget "_+.:E:S" '((-4 . "<OR") (0 . "ASTBOLTMID") (0 . "ASTBOLTCORNER") 

 

                              (0 . "ASTBOLTEDGE") (0 . "ASTBOLTSLOTTED") 

 

                              (0 . "ASTBOLTCIRCULAR") (0 . "ASTBOLTARRAY")

 

                              (0 . "ASTBOLTSTAGGERED") (0 . "ASTBOLTCOLLARED") 

 

                              (0 . "ASTBOLTCENTRAL") (0 . "ASTBOLTCOUPLER") (-4 . "OR>"))))

 

  

 

  ;; Check if a bolt is selected

 

  (if ss

 

    (progn

 

      ;; Get the first selected entity (bolt)

 

      (setq ee (ssname ss 0))

 

      

 

      ;; Get bolt handle

 

      (setq boltHandle (vla-get-Handle (vlax-ename->vla-object ee)))

 

      

 

      ;; Prompt user to choose between adding or removing objects

 

      (setq userChoice (getstring T "\nEnter 'add' to add objects or 'remove' to remove objects: "))

 

      

 

      ;; Add or Remove based on user input

 

      (cond

 

        ;; Add objects to the bolt connection

 

        ((= userChoice "add")

 

         (progn

 

           (setq connectionObj (ssget "\nSelect objects to add to the bolt connection: "))

 

           (if connectionObj

 

             (progn

 

               ;; Get handles of selected objects

 

               (setq objectHandles

 

                 (mapcar

 

                   (lambda (e) (vla-get-Handle (vlax-ename->vla-object e)))

 

                   (mapcar 'cadr (ssnamex connectionObj))

 

                 )

 

               )

 

               ;; Use the actual Advance Steel API function

 

               (AstAddObjectstoBolt boltHandle objectHandles)

 

               (princ "\nObjects added to the bolt connection.")

 

             )

 

             (princ "\nNo objects selected.")

 

           )

 

         )

 

        )

 

        

 

        ;; Remove objects from the bolt connection

 

        ((= userChoice "remove")

 

         (progn

 

           (setq connectionObj (ssget "\nSelect objects to remove from the bolt connection: "))

 

           (if connectionObj

 

             (progn

 

               ;; Get handles of selected objects

 

               (setq objectHandles

 

                 (mapcar

 

                   (lambda (e) (vla-get-Handle (vlax-ename->vla-object e)))

 

                   (mapcar 'cadr (ssnamex connectionObj))

 

                 )

 

               )

 

               ;; Use the actual Advance Steel API function

 

               (AstRemoveObjectsfromBolt boltHandle objectHandles)

 

               (princ "\nObjects removed from the bolt connection.")

 

             )

 

             (princ "\nNo objects selected.")

 

           )

 

         )

 

        )

 

        

 

        ;; Handle invalid input

 

        (T (princ "\nInvalid input. Please enter 'add' or 'remove'.")))

 

    )

 

    (princ "\nNo bolt selected."))

 

  (princ))

 

The Error I Encounter:

 

When I run this code and follow the prompts, this is the error I get after selecting a bolt and entering "add" or "remove":

 

Select objects:

Enter 'add' to add objects or 'remove' to remove objects: add

_undo Current settings: Auto = On, Control = All, Combine = Yes, Layer = Yes

Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back] <1>: _e

Command: _undo Current settings: Auto = On, Control = All, Combine = Yes, Layer = Yes

Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back] <1>: ADDBOLTTOCONNECTION

Command: "INTERNAL error in FAIL

message lost, reset to top"

 

What I Tried So Far:

 

I suspect the issue lies in the getstring function, which might be interpreting my input as a command.

 

I tried using T as an argument to getstring to force the input as a string, but it didn't resolve the issue.

 

I also made sure to handle the cases for invalid input, but the error seems to occur before that.

 

Any help would be greatly appreciated.

 

Thanks in advance!

 

 

 

0 Likes
267 Views
2 Replies
Replies (2)
Message 2 of 3

ec-cad
Collaborator
Collaborator

Search for InitGet function here or in Help, for the User input to Add or Remove.

 

Also, be aware that the ssget function, while active, allows for 'automatic' add of items.

You can also, add items , remove items, then add some more. Keeps on going until you

select 'nothing' or Enter Key.

Sample:

"Select Objects".... pick one at a time

"Select Objects" .. type in r or R to remove.

"Select Objects" .. type in a or A to add..

"Select Objects" .. type w or W to add all in a Window..

"Select Objects" .. type c or C to add all in Crossing..

 

 

ECCAD

0 Likes
Message 3 of 3

Sea-Haven
Mentor
Mentor

"Select Objects" .. type in r or R to remove." Also say select multiple objects, hold shift down and select objects to remove.

0 Likes