Rotate MText with individual Object Data Value

Rotate MText with individual Object Data Value

S.Röder
Participant Participant
1,546 Views
9 Replies
Message 1 of 10

Rotate MText with individual Object Data Value

S.Röder
Participant
Participant

Hello,

 

I have loaded a GML file (NAS format or German ALKIS data) into AutoCAD Map via MAPIMPORT with attached Object Data for the GIS attributes. All imported text objects (Mtext) are displayed with rotation 0 in the drawing.

 

In the attached OD attributes there is an individual angle of rotation ("drehwinkel") in radians for each text. I would now like to use LISP to check for all texts in the drawing whether the respective text has such an OD attribute and, if so, uses it as the rotation angle.

 

Attached is a screenshot to clarify what I want to do. Also a test file.

 

Can someone help me? Suggested solutions are welcome.

 

Thank you for your support!

0 Likes
Accepted solutions (2)
1,547 Views
9 Replies
Replies (9)
Message 2 of 10

pbejse
Mentor
Mentor

The Object Data attribute doesnt seem to appear on Vanilla CAD.

I even tried opening the file with MAP 2017. It shows this message "Drawing database is broken or unaccessible"

Is it because i used DwgTrueView to save the file to older version?

 

0 Likes
Message 3 of 10

S.Röder
Participant
Participant

I work with AutoCAD Map 3D Version 2020. The DWG is therefore saved in the 2018 format. Attached is the test file in 2013 DWG format.

 

I don't get any errors. The appended object data attributes of the object data table "AP_PTO" can be found in the properties of the Mtexts.

0 Likes
Message 4 of 10

pbejse
Mentor
Mentor
Accepted solution

@S.Röder wrote:

appended object data attributes of the object data table "AP_PTO" can be found in the properties of the Mtexts.


(defun c:Rotstring (/ GetFLD ss i e ent)
  (defun GetFLD	(TABLE FIELD EN / RecNO FldVAL)
    (setq RecNO	 (ade_odgetrecord EN TABLE 0)
	  FldVAL (ade_odgetrecfield RecNO FIELD)
    )
  )
  (if
    (setq ss (ssget "_:L" '((0 . "MTEXT"))))
     (repeat (setq i (sslength ss))
       (setq e	 (ssname ss (setq i (1- i)))
	     ent (entget e)
       )
       (if (setq rot (GetFLD "AP_PTO" "drehwinkel" e))
	 (entmod (subst (cons 50 rot) (assoc 50 ent) ent))
       )
     )
  )(princ)
)

HTH

 

Message 5 of 10

braudpat
Mentor
Mentor

Hello Mr @pbejse 

 

Thanks a beautiful and short routine !

 

The Health, Bye, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 6 of 10

S.Röder
Participant
Participant

Many thanks for the quick response! The code works fine.

 

At the moment the texts to be rotated have to be selected manually. How can I adapt the code so that all Mtexts are rotated automatically?

 

Thanks in advance.

0 Likes
Message 7 of 10

braudpat
Mentor
Mentor

Hello @S.Röder 

The Lisp can be updated to select automatically ALL objects of the DWG (No selection) !

But you can also use the option "ALL" (or "_ALL" if Non US/English AutoCAD !?) when selecting objects ... It is too long for you !?

The Health, Bye, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 8 of 10

pbejse
Mentor
Mentor
Accepted solution

@S.Röder wrote:

At the moment the texts to be rotated have to be selected manually. How can I adapt the code so that all Mtexts are rotated automatically?


Sure, just make sure there are no MTEXT on locked layer.

Change this 

(setq ss (ssget "_:L" '((0 . "MTEXT"))))

to

(setq ss (ssget "_X" '((0 . "MTEXT"))))

HTH

 

Message 9 of 10

S.Röder
Participant
Participant
Thank you for your answer.
0 Likes
Message 10 of 10

Ross_Stratford
Community Visitor
Community Visitor

Hi, I'm trying to use this but I'm  working in decimal degrees what parts need to be changed? 

0 Likes