Reading from a closed polyline name (TEXT 1) and selecting and adding other TEXT 2 elements to the table

Reading from a closed polyline name (TEXT 1) and selecting and adding other TEXT 2 elements to the table

biletbilet
Observer Observer
525 Views
5 Replies
Message 1 of 6

Reading from a closed polyline name (TEXT 1) and selecting and adding other TEXT 2 elements to the table

biletbilet
Observer
Observer

Hello

 

I'm just starting my adventure with lisps, and need tips from experienced colleagues.

 

I woud like to take two types of text from a closed polylines which are on specific layer

 

TEXT 1 – name on layer 1 – Always one text object inside polyline

TEXT 2 – names on layer 2- from one to x elements inside polyline

 

And all data informations should go to the table below

 

The problem for me is not selecting a polline, selecting one element or inserting to the table, but selecting name „TEXT 1” and repeating it in the lines depending on the number of „TEXT 2” elements.

Hoping someone  can help me with this.

 

MicrosoftTeams-image (4).png

0 Likes
Accepted solutions (1)
526 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant

Welcome to the Forums!

I am not sure I understand you... would you post the code of the portion that you have "no problem" with? 

0 Likes
Message 3 of 6

Mehmet_Demiryurek
Mentor
Mentor
Accepted solution

@biletbilet 

I wrote a lisp based on the drawing you shared.
Green text LAYER1
Blue text LAYER2

If the conditions are met, these values are transferred into a table.
If there is more than one green text, the value of the first selected text is accepted.

Its development is up to you.

 

 

(defun c:TESTTABLE (/ ss c tek koor )
     (setq obj (vlax-get-acad-object))
     (setq doc (vla-get-ActiveDocument obj))
     (setq mspace (vla-get-modelspace doc))  
(if (setq ss (ssget (list (cons 0 "LWPOLYLINE"))))
  (progn
    (setq c 0 say (sslength ss) lst '())
    (while (< c say)
      (setq tek (ssname ss c)
	    koor (mapcar 'cdr (vl-remove-if '(lambda (x)(/= (car x) 10)) (entget tek))))
      (if (setq lyr-1-sec (ssget "_WP" koor '((0 . "TEXT")(8 . "LAYER1"))))
	(progn
        (setq lyr-1-nmbr (cdr (assoc 1 (entget (ssname lyr-1-sec 0))))
	      txt-hg (cdr (assoc 40 (entget(ssname lyr-1-sec 0)))))
	(if (setq lyr-2-sec (ssget "_WP" koor '((0 . "TEXT")(8 . "LAYER2"))))
	  (progn
	    (setq nw-lst '() d 0)
	    (repeat (sslength lyr-2-sec)
	      (setq lyr-2-tek (ssname lyr-2-sec d)
		    lyr-2-str (cdr (assoc 1 (entget lyr-2-tek)))
		    nw-lst (cons (cons lyr-1-nmbr lyr-2-str) nw-lst)
		    d (1+ d))
	      )
	    (setq lst (append lst nw-lst))))
	))
      (setq c (1+ c))
      )
   (setq yeni-lst (vl-sort lst '(lambda (a b)(< (car a)(car b)))))
(if (setq pt (getpoint "\nSpecify insertion point:"))
  (progn
    (setq mytbl	(vla-addtable
		  mspace
		  (vlax-3d-point pt)
		  (+ (length lst) 2)
		  2
		  (* (fix txt-hg) 2)
		  (* (* (fix txt-hg) 1.4) 5.0)
		)
    )
(vla-setcellvalue mytbl 0 0 "TABLE")  (vla-setcelltextheight mytbl 0 0 (fix txt-hg))    
(vla-setcellvalue mytbl 1 0 "LAYER 1")(vla-setcelltextheight mytbl 1 0 (fix txt-hg))
(vla-setcellvalue mytbl 1 1 "LAYER 2")(vla-setcelltextheight mytbl 1 1 (fix txt-hg))
(setq z 2)
(foreach n yeni-lst
  (vla-setcellvalue mytbl z 0 (car n))(vla-setcelltextheight mytbl z 0 (fix txt-hg))(vla-setcellalignment mytbl z 0 acMiddleCenter)
  (vla-setcellvalue mytbl z 1 (cdr n))(vla-setcelltextheight mytbl z 1 (fix txt-hg))(vla-setcellalignment mytbl z 1 acMiddleCenter)
  (setq z (1+ z)))
   ))
    ))
  (princ))

 

 

 


Mehmet Şamil DEMİRYÜREK

Bu gönderiyi faydalı buldunuz mu? Bu gönderiyi beğenmekten çekinmeyin.
Sorunuz başarıyla yanıtlandı mı? ÇÖZÜMÜ KABUL ET düğmesine tıklayın.


EESignature

Linkedln

Message 4 of 6

biletbilet
Observer
Observer

@Mehmet_DemiryurekYou are a genius 🙂 I would never come to it alone. I've made some my own changes and it works perfectly 🙂 I attach the finished lisp file and the test file. Thanks again for your help.


Changes made by me:
1. I added at the beginning (vl-load-com)

2. I wrote a script that selects all closed polylines on the layer "0002 Room boundary" - Polish name
(setq ss (ssget "X" (list '(0. "LWPOLYLINE")
'(70. 1)
(cons 8 "0002 Room boundary"))))

3. I changed TEXT to TEXT and MTEXT
(ssget "_WP" koor '((0. "TEXT, MTEXT") (8. "LAYER2"))))

What does "koor" mean?

 

I have a question about another question, how to insert a dialog window that opens after typing the startup command lisp, in which I can describe how does it work?
One more question, can you provide some entry-level information for data entry dialogs?

 

Thanks alot once againt

0 Likes
Message 5 of 6

Mehmet_Demiryurek
Mentor
Mentor

Thank you for the nice words.
The word "Koor" is an abbreviation of "Coordinate" in my language. ie Coordinate.
Coordinate list of the corner points of the selected polyline object.

You can use the "Alert" command for the popup dialog.

(alert "\nThis is a test message")

It would take a long time to provide information here for the introduction dialog windows and detailed explanation.

You can benefit from the site in the link related to the topic of Dcl.
Wishing you success..

 

https://www.afralisp.net/dialog-control-language/


Mehmet Şamil DEMİRYÜREK

Bu gönderiyi faydalı buldunuz mu? Bu gönderiyi beğenmekten çekinmeyin.
Sorunuz başarıyla yanıtlandı mı? ÇÖZÜMÜ KABUL ET düğmesine tıklayın.


EESignature

Linkedln

0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

Alert this is the instructions press ok when happy.

 

 

 

(alert "this is the instructions on how to use
\nThis is the next line of instructions
\n the next line again
\and ono another new line 
\nglad this is the end")

 

 

One of the things I often do is select an object and get that objects name and use that in the ssget that way its not hard coded.

 

There is no quick how to do dcl there is help and I am lucky and have a paper copy bit easier to see which bit of dcl your trying to understand.

 

Over at Cadtutor did do something which was convert dwg objects to DCL code so you can see how it works. It is very rough code but produces a result. Its only 1st step just put it out there to see how much interest.

 

make a dcl from dwg objects - AutoLISP, Visual LISP & DCL - AutoCAD Forums (cadtutor.net)

This took a little while to put together. It has edit box's, radio buttons and toggles.

SeaHaven_0-1668320554377.png

 

0 Likes