How to read AutoCAD Entity Transformation Matrix

How to read AutoCAD Entity Transformation Matrix

salman_abeed
Enthusiast Enthusiast
6,849 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,850 Views
29 Replies
Replies (29)
Message 21 of 30

salman_abeed
Enthusiast
Enthusiast

thanks @ActivistInvestor 

 

I try the code and it seems to be working. Initially I was getting exceptions and then I saw that some of the functions are not implemented as below. So I commented so they won't through and by putting a break point I can see that I am getting call back and different data is coming in these functions but as these functions are not doing anything so there is no result in editor

 

public void Insert(int index, DwgDataItem item)
{
// throw new NotSupportedException("The instance is read-only");
}

public void RemoveAt(int index)
{
// throw new NotSupportedException("The instance is read-only");
}

public void SetValueAt(int index, object value)
{
// throw new NotSupportedException("The instance is read-only");
}

public void Add(DwgDataType type, object value)
{
// throw new NotSupportedException("The instance is read-only");
}

public void Add(TypedValue value)
{
// throw new NotSupportedException("The instance is read-only");
}

public virtual void Add(DwgDataItem item)
{
// throw new NotSupportedException("The instance is read-only");
}

public void Clear()
{
// throw new NotSupportedException("The instance is read-only");
}

0 Likes
Message 22 of 30

daniel_cadext
Advisor
Advisor

As my signature (https://github.com/CEXT-Dan/PyRx)

 

but it’s the same concept ARXDBG / MGDDBG (DWG Copy filer)

https://github.com/ADN-DevTech/MgdDbg

 

Investors filer looks pretty slick too, I’d give that a whirl if you’re in C#

 

I noticed one of the ByteArrays changed when I rotated a beam, I’d bet it’s a World -Direction Xdata, but mine can’t read it, maybe another can

 

Cheers : )

 

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

ActivistInvestor
Mentor
Mentor

Before I committed that file, I made the class read-only, by gutting all of the methods that modify it, replacing it with throw NotImplementedException(), because there isn't really any need for it and it was never tested.

 

But, one of the functions that I gutted is needed, so that's the problem.

 

Just add the code below to the class and that should fix it, or download the revised version that I just committed.

 

 

void Add(DwgDataType type, object value)
{
   data.Add(new DwgDataItem(type, value));
}

 

 

The file also adds the DwgDump() extension method to DBObject that will output the DWG filer data to the console.

 

Message 24 of 30

ActivistInvestor
Mentor
Mentor
Accepted solution

After the first revision to resolve the error you were getting, I discovered that there was many other issues with this code, that I had never dealt with (mostly because I was only using it to grab ObjectId references to other objects, and didn't concern myself with any other aspects of it and it has been sitting unused for many years). 

 

To resolve most (but not all) of those issues I've had to make some revisions which are now in the latest commit.

Message 25 of 30

salman_abeed
Enthusiast
Enthusiast

thanks ... I am going to try latest 

 

There are few more types not covered .. maybe a minute for you to add them in the best way.


case DwgDataType.UInt32: 
case DwgDataType.UInt16: 

case DwgDataType.Real: 

0 Likes
Message 26 of 30

salman_abeed
Enthusiast
Enthusiast

Nice ... its working nicely ignore my previous request... I see we don't need DXF conversion.

 

 

There is one minor issue with the code. on my side I have indexes started at 0 so next line was crashing

return string.Format("\n{1}: {2}", this.DataType, val);

corrected to

return string.Format("\n{0}: {1}", this.DataType, val);

 

I accepted it as a solution. Great work

0 Likes
Message 27 of 30

ActivistInvestor
Mentor
Mentor

Thanks for pointing out that bug, I've fixed it and posted an update.

 

XData is persisted as binary data, but that shouldn't be a problem since you can get the XData from the DBObject's XData property.

0 Likes
Message 28 of 30

ActivistInvestor
Mentor
Mentor

@salman_abeed wrote:

thanks ... I am going to try latest 

 

There are few more types not covered .. maybe a minute for you to add them in the best way.


case DwgDataType.UInt32: 
case DwgDataType.UInt16: 

case DwgDataType.Real: 


 

If you're talking about the code that converts items to TypedValues, I'm depreciating that because it just doesn't work. I did add a case for DxfCode.Real, but there is no DXF output that uses unsigned integers and there are no DxfCodes that represent those types:

 

case DwgDataType.UInt32:
   return new TypedValue((short) DxfCode.???????, Value)
case DwgDataType.UInt64:
   return new TypedValue((short) DxfCode.???????, Value)

 

There's no direct correlation between DwgDataType and DxfCode. For example, there are several DxfCode fields that all have the same numeric value of 41. ToString() will always show you the first one that appears in the enum declaration, which is not meaningful. It may represent the width factor of a TEXT entity; the X scale factor of an INSERT entity; or a VIEWPORT's aspect ratio. So, the same DxfCode can have a different meaning for each type of entity whose DXF output it appears in.

 

For DWG output, the latest version marshals a list of DwgDataItem structs that use the DwgDataType enum to describe the type. DwgDataType conveys both a data type, and a sub-type (e.g., what type of reference an ObjectId represents). But unlike DxfCodes, a DwgDataType does not convey what a value represents, because that can be object type-dependent and/or order-dependent. I will probably remove all of the TypeValue/DxfCode-related code because it only confuses interpretation of the output.

Message 29 of 30

daniel_cadext
Advisor
Advisor

For Python wrappers, I just return a list of tuples with the Type as a string, in this case I was interested which overload gets called DwgDataType just tells you its an kDwg3Real, Interested to see what you come up with.

Edit, Probably redundant in .NET, but in python, there’s no UInt8 or Int64, just an int

 

 

Acad::ErrorStatus PyDbSnoopDwgFiler::writeVector2d(const AcGeVector2d& val)
{
    PyAutoLockGIL m_lock;
    m_list.append(boost::python::make_tuple("AcGeVector2d", val));
    return eOk;
}

Acad::ErrorStatus PyDbSnoopDwgFiler::writeVector3d(const AcGeVector3d& val)
{
    PyAutoLockGIL m_lock;
    m_list.append(boost::python::make_tuple("AcGeVector3d", val));
    return eOk;
}

Acad::ErrorStatus PyDbSnoopDwgFiler::writeScale3d(const AcGeScale3d& val)
{
    PyAutoLockGIL m_lock;
    m_list.append(boost::python::make_tuple("AcGeScale3d", val));
    return eOk;
}

 

 

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

ActivistInvestor
Mentor
Mentor

The managed DwgFiler has no overloaded WriteXxxxx method as the native filer has, there's an explicit  method for writing each type, so I don't need to know that. I was thinking about swapping managed types for DwgDataTypes in the DwgDataItem struct, or just adding a Type property that returns it, since it's a simple mapping, but then they can just call GetType() on the Value.