LISP to Create automatic terminal block

LISP to Create automatic terminal block

sada20LQDYV
Contributor Contributor
550 Views
7 Replies
Message 1 of 8

LISP to Create automatic terminal block

sada20LQDYV
Contributor
Contributor

Hello,

I am looking for or would like to create a lisp capable of creating terminals automatically. I will indicate the position point by pointing with the mouse of the terminal block and I will select the terminals as in the drawing that I attached. The terminals are in folios 02 and 03 for example and the terminal block is on folio10. I would also like to pass on the wire number.

could you help me please?

 

 

0 Likes
Accepted solutions (1)
551 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

Below are the changes I made:
I'm not sure if you only want to select 1 Block at a time but if you do then change the following:

(setq ss (ssget '((0 . "INSERT") (2 . "POINTBORNE"))))

To this:

; filter selection to only 1 block
  (setq ss (ssget "_+.:E:S" '((0 . "INSERT") (2 . "POINTBORNE"))))

If selected item then first things to do are the following:

      (setq ss (ssname ss 0)) ; get entity of first/only item in selection set
      (setq attreq (getvar"attreq")) ; save current setting
      (setvar "attreq" 0) ; set attribute value prompt off

Then instead of these lines of code that doesn't work:

;      (setq nbornier (entget (car ss) '("NBORNIER")))
;      (setq nbornier (cdr (assoc 1 nbornier)))
;      (setq pborne (entget (car ss) '("PBORNE")))
;      (setq pborne (cdr (assoc 1 pborne)))
;      (setq nfils (entget (car ss) '("NFILS")))
;      (setq nfils (cdr (assoc 1 nfils)))
;      (setq ptborne (entget (car ss) '("POINTBORNE")))
;      (setq ptborne (cdr (assoc 10 ptborne)))

Use the following:

      (setq nbornier (getpropertyvalue ss "NBORNIER")) ; get block attribute values
      (setq pborne (getpropertyvalue ss "PBORNE"))
      (setq nfils (getpropertyvalue ss "NFILS"))
      (setq ptborne (cdr (assoc 10 (entget ss)))) ; get block's insertion point

Instead of the following to insert new block & fill out attributes:

      ;; Insertion du bloc "BORNIER"
;      (command "INSERT" "BORNIER" ptborne "1" "1" "0" "")
;      (setq bornier (entlast))
;      (command "-ATTEDIT" "1" bornier "" "ALL" nbornier "")

Use the following:

      ;; Insertion du bloc "BORNIER"
      (command "_.INSERT" "BORNIER" ptborne "1" "1" "0") ; insert block using selected block's insertion point
      (setpropertyvalue (entlast) "NBORNIER" nbornier) ; place value into inserted block's attribute

Then for inserting the next block instead of these lines of code:

      ;; Insertion des blocs "BORNE"
;      (setq borne_pt ptborne)
;      (repeat (length ss)
;        (command "INSERT" "BORNE" borne_pt "1" "1" "0" "")
;        (setq borne (entlast))
;        (command "-ATTEDIT" "1" borne "" "NFILS" nfils "")
;        (command "-ATTEDIT" "1" borne "" "PBORNE" pborne "")
;        (setq borne_pt (mapcar '+ borne_pt '(10 0))) ;; Décalage horizontal de 10 unités
;      )

Use the following:

      ;; Insertion des blocs "BORNE"
      (command "_.INSERT" "BORNE" ptborne "1" "1" "0") ; insert block using selected block's insertion point
      (setpropertyvalue (entlast) "PBORNE" pborne) ; place value into inserted block's attribute
      (setpropertyvalue (entlast) "NFILS" nfils) ; place value into inserted block's attribute

Now I'm not sure what you want to do with this...do you want to move this newly inserted block 10 units to the right?

;        (setq borne_pt (mapcar '+ borne_pt '(10 0))) ;; Décalage horizontal de 10 unités

After all done then restore original setting:

     (setvar "attreq" attreq) ; restore original setting

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 8

sada20LQDYV
Contributor
Contributor
Thanks for your answer For example, if I select 2 "POINTBORNE" blocks, I want the lisp to create a terminal block consisting of a "TERMINAL" block including the attribute name "nbornier" and 2 "TERMINAL" blocks with the 2 attributes "NFILS" and "PBORNE" and that it allows me to position the terminal block. if I select 5 "POINTBORNE" blocks that it puts me 5 "TERMINAL" blocks etc... with always a single "TERMINAL" block in front of the "POINTBORNE" blocks I can have several terminal blocks with different names in the attribute.
 
 
 
0 Likes
Message 4 of 8

sada20LQDYV
Contributor
Contributor

on the other hand, if the lisp that you made available to me, as soon as I select the first terminal (round) for example on sheet 3, POINTBORNE 01, it immediately creates the terminal block at the location of this terminal and sets me to offset the "TERMINAL BLOCK" block and the "TERMINAL" block I would like it to let me select all the desired terminals, and let me position the terminal block as for example in a place on sheet 10.

0 Likes
Message 5 of 8

paullimapa
Mentor
Mentor

Ok, now that you've clarified what you want try this revised version.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 8

paullimapa
Mentor
Mentor
Accepted solution

So this is the resulting Block combination graphic you have shown on Sheet 10:

paullimapa_0-1740690451340.png

To match this configuration, I've again revised the lisp code attached.

Since you want to be able to select multiple POINTBORNE blocks and each contain an attribute NBORNIER with the possibility of different values, I suggest you first pick the POINTBORNE block that contains the preferred NBORNIER attribute value which the lisp code will then use to fill out the inserted BORNIER block's Attribute value:

paullimapa_1-1740691511694.png

So given this drawing with 3 POINTBORNE blocks to select from with each containing a different attribute NBORNIER value

paullimapa_2-1740691876991.pngpaullimapa_3-1740692138775.png

 

And you want the inserted BORNIER block's attribute value to be B-003 then when you run lisp function CREER_BORNIER, you would first select POINTBORNE 03 and then use crossing window to select the rest.

After the code compiles the blocks as requested you'll be prompted to select a location to place it:

paullimapa_4-1740692349028.png

 

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 8

sada20LQDYV
Contributor
Contributor

Thank u so much, you 're incredible.

Thank you thank you.

0 Likes
Message 8 of 8

paullimapa
Mentor
Mentor

You are welcome…cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes