How to read AutoCAD Entity Transformation Matrix

How to read AutoCAD Entity Transformation Matrix

salman_abeed
Enthusiast Enthusiast
6,719 Views
29 Replies
Message 1 of 30

How to read AutoCAD Entity Transformation Matrix

salman_abeed
Enthusiast
Enthusiast

how to read the transformation matrix of a placed entity. I want to iterate over the whole model entities and read their origin and other angles

 

 

Regards

Salman

0 Likes
Accepted solutions (1)
6,720 Views
29 Replies
Replies (29)
Message 2 of 30

_gile
Consultant
Consultant

Hi,

You need to specify which entity types you're talking about. A transformation matrix makes sense for a BlockReference (a type that exposes a BlockTransform property), much less for a Circle or a Line.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 30

salman_abeed
Enthusiast
Enthusiast

these are custom entities viewable via Object Enabler

0 Likes
Message 4 of 30

_gile
Consultant
Consultant

@salman_abeed wrote:

these are custom entities viewable via Object Enabler


This does not help much.

You should attach some drawing sample and specify which Object Enabler you are using.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 30

salman_abeed
Enthusiast
Enthusiast

Attached is a prostructure file.  object enabler can be downloaded from here

https://communities.bentley.com/products/prostructures/m/drafting_and_detailing_gallery/274619

 

latest OE is for 2020 so not sure if you have older ACAD.

0 Likes
Message 6 of 30

_gile
Consultant
Consultant

It looks like there's no Object Enabler for AutoCAD R24 (2021-2024).

Anyway, I'm afraid a non Autodesk application Object Enabler does not provide any .NET API to allow access to the object properties.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 30

salman_abeed
Enthusiast
Enthusiast
anyother way apart from .NET?
0 Likes
Message 8 of 30

ActivistInvestor
Mentor
Mentor

1. DXFOUT

 

2. A custom DwgFiler class passed to DwgOut(), which will give you the data that an entity writes to a DWG file, but requires you to know something about the format/structure of that data (you will most-likely need to resort to reverse-engineering it). 

0 Likes
Message 9 of 30

salman_abeed
Enthusiast
Enthusiast

unfortunately nothing much is exposed in dxf. I solved a similar problem in the past(so I understand what you are saying) but in that case I can't see the dxf data like you said using ARXDBG.  Maybe they are just keeping it other then dxf

0 Likes
Message 10 of 30

daniel_cadext
Advisor
Advisor

If you have the enablers for an older version of AutoCAD , you can reverse engineer the filer, recreate the custom objects in ARX, not a trivial task though.

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 11 of 30

daniel_cadext
Advisor
Advisor

BTY, you can get the bounding box of the proxy, if that helps

 

(defun c:doit ()
  (vl-load-com)
  (setq util (vla-get-utility (vla-get-activedocument (vlax-get-acad-object))))
  (vla-getentity util 'obj 'ip "\nSelect Object: ")
  (vla-GetBoundingBox obj 'minpoint 'maxpoint)
  (print(vlax-safeArray->list minpoint))
  (print(vlax-safeArray->list maxpoint))
  (princ)
)
Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 12 of 30

ActivistInvestor
Mentor
Mentor

You said you looked at the data using ArxDbg. Did you look at a dxf file created from a drawing containing some of these custom objects? Are they round-tripped by DXFOUT/DXFIN?

 

Don't rely too heavily on arxdbg to Snoop the drawing file, because it only can display what it was very-explicitly programmed to display, and anything it doesn't understand it will not show you.

 

And finally, there is the custom DwgFiler file approach which may or may not work depending on how the custom object files out its data. If it files it out as binary data/BLOB, then you would have much more reverse-engineering to do. 

0 Likes
Message 13 of 30

salman_abeed
Enthusiast
Enthusiast

Thanks... making sense.

Can I read from DwgFiler in .NET or I have to use C++? Is there some sample code for this .... I used it 15 years back?

0 Likes
Message 14 of 30

salman_abeed
Enthusiast
Enthusiast

Unfortunately not as shape is not symmetrical so I can't fit the beam just relying on that.

0 Likes
Message 15 of 30

daniel_cadext
Advisor
Advisor

Has the goal changed? The topic was getting the Transformation, what is required for fitting beams?

 

You can get a lot of information from the bounding box with some context, i.e. if you have a collection of objects 2x4x some extrusion length, you know they are beams. You also have different types Ks_Bolt, Ks_Shape, Ks_Plate you can filter with. Most parts will have a common dimension you can extrapolate from

 

Reverse engineering the filer may help you get a better idea of position and dimensions, but it’s another thing to make the object behave in a certain way.

 

You can read the filer from .NET, you can use MgdDbg as an example, you need to have a running enabler though.  

You’d need C++ to recreate an entity. I’ve done it, it takes a bunch of prodding and probing to figure out what each item in the filer does

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 16 of 30

ActivistInvestor
Mentor
Mentor

No C++ required (it and C# have fallen out of fashion anyhow, in favor of Rust).

 

At this link you will find a file that should serve as a starting point. Caveat emptor, this is very old code that hasn't been touched in a very long time, and was mainly used for debugging/diagnostics, and I don't even remember if it had any unresolved issues, so there's no warrantee of any kind.

Message 17 of 30

daniel_cadext
Advisor
Advisor

I have a snoop filer in python, looks like there's lots of data, this is from one of the beems

 

import PyRx as Rx
import PyGe as Ge
import PyGi as Gi
import PyDb as Db
import PyAp as Ap
import PyEd as Ed
import PyGs as Gs
 
def PyRxCmd_doit():
    try:
        snoop = Db.SnoopDwgFiler()
        entRes = Ed.Editor.entSel("\nSelect: ")
        if entRes[0] != Ed.PromptStatus.eNormal:
            return
        ent = Db.Entity(entRes[1])
        ent.snoop(snoop)
        print(snoop.buffer())
 
    except Exception as err:
        print(err)
 

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 18 of 30

daniel_cadext
Advisor
Advisor

BTW The ByteArray sections are most likely XData, I didn’t write the conversion for that. Maybe ActivistInvestor’s has that

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 19 of 30

daniel_cadext
Advisor
Advisor
A bit of a tangent, I do want to try Rust. C++ / Rust interop looks very difficult, I doubt there way to load Rust modules into AutoCAD. But still might be fun to play with. Python is super fun just because of the huge amount of modules and garbage collection is predictable, not exactly fast though
Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 20 of 30

salman_abeed
Enthusiast
Enthusiast

thanks @daniel_cadext 

 

Where is this python code available. Can I use it to try it out on my machine to snoop entities?

 

This is what I am looking for though my rest of the code is in C# so I am not sure if python can work in parallel but if I can call Python from c# then it will help.

0 Likes