Select text inside closed polylines and define block atributtes with that text.

Select text inside closed polylines and define block atributtes with that text.

Anonymous
Not applicable
3,542 Views
25 Replies
Message 1 of 26

Select text inside closed polylines and define block atributtes with that text.

Anonymous
Not applicable
I have an floor-plan drawing with several rooms defined by an enclosed polyline. There are several text annotations inside each polyline (room-number, room-name, etc).
How can i make a routine thats scans the drawing, builds a selectionset that finds each polyline (resides on a specific layer) and creates a block (room_stamp) with attributes corresponding to those annotations. 
E.g.: for every room it would insert the block "room_stamp" inside the polyline, grab the text inside the polyline which belongs to the layer "room_name" and change the attribute "room_name" inside the block to match it.

Any help would be apreciated as I am just starting with LISP routines.
0 Likes
3,543 Views
25 Replies
Replies (25)
Message 2 of 26

devitg
Advisor
Advisor

@Anonymous For better understanding, and maybe get further help, please upload such sample.dwg

 

 

0 Likes
Message 3 of 26

JBerns
Advisor
Advisor

@Anonymous,

 

Could you provide a sample drawing? Simplify as needed.

 

Perhaps you could acquire the coordinates of the "room" polylines and then use each one in turn to perform a polygon window selection. Filter for the text objects in the selection. Insert the block with attributes from the acquired text information. Repeat the process for all "rooms".

 

The sample drawing will be helpful to further advise. 

 

Regards,

Jerry

 

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 4 of 26

JBerns
Advisor
Advisor

@Anonymous,

 

It would appear this question has been asked before and various solutions exist.

 

Solved: Convert text to attribute - Autodesk Community - AutoCAD Architecture 

CAD Forum - How to convert texts to block attributes (references)? 

AutoCAD convert text to block definition and update text - YouTube 

Convert Text Into Attributes (TEXT2ATTRIB) 

AutoLISP to convert text to block - AutoLISP, Visual LISP & DCL - AutoCAD Forums 

Automatically Convert Text or Mtext to Attributes | CAD Tips  

Replace text with block and transfer value into attribute 

 

Please see if these links can be of assistance. If not, we can further assist after the sample drawing is reviewed.

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 5 of 26

JBerns
Advisor
Advisor

@Anonymous,

 

Take a look at the last link above.

Replace text with block and transfer value into attribute 

 

There is a solution provided by the AUGI member named, Peter.

His solution is an AutoLISP routine named, RoomNumber.

It may be very close to what you need.

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 6 of 26

pbejse
Mentor
Mentor

@Anonymous wrote:
Any help would be apreciated as I am just starting with LISP routines.

Are you asking for guidance to help you build the code on your own?

or are you requesting for a working routine that will to the task you just describe on your post?

 

If its the latter, then @JBerns provided  more than enough links so you can pick and choose one the at works best for you. I'm sincerely hoping its the former though.

 

 

 

 

0 Likes
Message 7 of 26

Anonymous
Not applicable

Thank you all for your answers. Please find a simplified DWG sample here attached.

I'm currently going through the links suggested.

0 Likes
Message 8 of 26

Anonymous
Not applicable

It is definitely the former, as I'm looking to build the exact routine for my specific problem.

0 Likes
Message 9 of 26

JBerns
Advisor
Advisor

@Anonymous,

 

Thank you for the sample drawing.

In the sample drawing, there are three (3) MText objects "inside" the room perimeter.

Is it your intention that all three MText objects become three attributes of a block?

I noticed that the position of the upper-right MText object varies in spacing to the other MText objects depending on the size of the room. Is that your intention?

 

Possible workflow:

  • Test that the room detail block is defined (actual name to be determined)
  • Create a selection set of all the LWPolylines on the Room layer
  • If objects are found that meet the criteria, begin a loop
  • For each LWPolyline, create a selection set from a Window Polygon (WP) selection based on the coordinates of the LWPolyline. Special methods will be required if there are any non-linear segments in the LWPolyline.
  • If the selection finds three MText objects on the RName, RNumber, and RFunction layers, acquire the text object information, and then insert the block using the text object information.
  • What should happen if three text objects are not found? Insert block with information found or skip the room?
  • The position of the "function" attribute will need to be adjusted based on the position of the original text object
  • When loop of LWPolylines is complete, report the number of blocks inserted. Report any "skipped" rooms.

 

I would welcome input on other possible workflows to solve the challenge.

 

Curious - how many rooms do you have to process? How many drawings? Depending on the number may determine the complexity of the automation solution.

 

 

Regards,

Jerry

 

 

 

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 10 of 26

ВeekeeCZ
Consultant
Consultant

The first and last polyline are very nice - need special treatment.

0 Likes
Message 11 of 26

devitg
Advisor
Advisor

@ВeekeeCZ wrote:

The first and last polyline are very nice - need special treatment.


@ВeekeeCZ , about the poly 1 and 3 , WHY? and HOW? to treat

 

 

 

0 Likes
Message 12 of 26

devitg
Advisor
Advisor

@ВeekeeCZ I got it , this DWG , comes from  MICROSTATION 

0 Likes
Message 13 of 26

JBerns
Advisor
Advisor

@devitg,

Perhaps that is why I am having trouble processing the non-rectangular polylines.

I exploded the non-rectangular polylines, then used PEDIT to rejoin the line segments.

Now my test code is working.

Wonder what is different about those two non-rectangular polylines.

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 14 of 26

JBerns
Advisor
Advisor

@devitg,

 

Disregard last message, the exploded-rejoined polylines solution is now not working.

Strange that it worked for a few cycles of my code.

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 15 of 26

JBerns
Advisor
Advisor

Interesting - the long room and the L-shaped room have a negative Z extrusion direction.

 

(210 0.0 0.0 -1.0)

 

Now I know why the Window Polygon selection wasn't working.

 

Any thoughts how to flip the extrusion direction? Would we need to use a coordinate translation?

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 16 of 26

devitg
Advisor
Advisor

@JBerns  I solve it , with the OP collaboration  , getting the poly coordinates to use at SSGET by this

(defun _pac (e / l v d lst)
   (setq d (- (setq v (/ (setq l (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))) 100.))))
   (while (< (setq d (+ d v)) l)
     (setq lst (cons (vlax-curve-getPointAtDist e d) lst))
   )
 )

Do not ask me why, how, or so . IT WORK . 

 

Message 17 of 26

devitg
Advisor
Advisor

@JBerns  about normal , I got it from the vlide help 

 

;; Change the normal for the pline
    (setq newNormal (vlax-3d-point 1 1 1))
    (vla-put-Normal plineObj newNormal)
    (vla-Update plineObj)
    (setq newNormal (vlax-variant-value newNormal))
    (alert (strcat "The current normal for the circle is " (rtos (vlax-safearray-get-element newNormal 0) 2) ", "
                                                           (rtos (vlax-safearray-get-element newNormal 1) 2) ", "
                                                           (rtos (vlax-safearray-get-element newNormal 2) 2)))
)
0 Likes
Message 18 of 26

devitg
Advisor
Advisor

I forget to mention the author of 

(defun _pac (e / l v d lst)
   (setq d (- (setq v (/ (setq l (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))) 100.))))
   (while (< (setq d (+ d v)) l)
     (setq lst (cons (vlax-curve-getPointAtDist e d) lst))
   )
 )

this .

it is part of 

;; Select Within Curve
BY ;; Alan J. Thompson, 03.31.11

 

0 Likes
Message 19 of 26

ВeekeeCZ
Consultant
Consultant

@devitg wrote:

I forget to mention the author of 

(defun _pac (e / l v d lst)
   (setq d (- (setq v (/ (setq l (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))) 100.))))
   (while (< (setq d (+ d v)) l)
     (setq lst (cons (vlax-curve-getPointAtDist e d) lst))
   )
 )

this .

it is part of 

;; Select Within Curve
BY ;; Alan J. Thompson, 03.31.11

 


 

@devitg 

thanks for this tip. The important message of this is that the VLA-CURVE* functions return correct coordinates.

 

While the algorithm might look complicated, it's rather simple: the function divides pl's overall lengths into 100 pieces and returns coords of each 100 points (not necessarily at original vertices). 

 

While all polylines from the OP's example are without bulges, a more suitable algorithm would be just to use coords of all current vertices. Like the following example

 

(repeat (setq p (fix (vlax-curve-getendparam e)))
  (setq v (cons (vlax-curve-getpointatparam e (setq p (1- p))) v)))

 

 
0 Likes
Message 20 of 26

JBerns
Advisor
Advisor

This code could be used to test each polyline to determine if it contains an arc segment.

(vl-member-if-not
  'zerop
  (mapcar 'cdr
	  (vl-remove-if-not
	    '(lambda (x) (= (car x) 42))
	    (entget (car (entsel)))
	  )
  )
)

 

The code builds a list of bulge factors from the selected polyline. The list is tested if it contains any non-zero values. If a non-zero value is found, a partial list is returned. If all list values are zero, nil is returned.

 

@Anonymous, an arc segment is indicated by the presence of a non-zero value in the 42 (bulge factor) group code. Learn more at (Lee Mac - Bulge Conversion) about bulge factor. Shown here is a polyline with one line segment and one arc segment:

 

((-1 . <Entity name: 180f4c18940>) (0 . "LWPOLYLINE") (330 . <Entity name: 180c6fa01f0>) (5 . "48C") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbPolyline") (90 . 3) (70 . 0) (43 . 0.0) (38 . 0.0) (39 . 0.0) (10 1795.06 1856.21) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 1796.06 1856.21) (40 . 0.0) (41 . 0.0) (42 . 0.374809) (91 . 0) (10 1796.06 1856.73) (40 . 0.0) (41 . 0.0) (42 . 2.25417) (91 . 0) (210 0.0 0.0 1.0))

 

If the polyline is determined to have an arc segment, one could use the code by Alan J. Thompson. If all line segments are present, then use the code shown by @ВeekeeCZ.

 

 

Regards,

Jerry 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes