This simple C# code returns null for "ASobject" variable in AS2019. In previous AS versions works correctly.
Autodesk.AdvanceSteel.CADLink.Database.ObjectId objId = UserInteraction.SelectObject(); AtomicElement ASobject = DatabaseManager.Open(objId) as AtomicElement;
What is the reason?
Solved! Go to Solution.
This simple C# code returns null for "ASobject" variable in AS2019. In previous AS versions works correctly.
Autodesk.AdvanceSteel.CADLink.Database.ObjectId objId = UserInteraction.SelectObject(); AtomicElement ASobject = DatabaseManager.Open(objId) as AtomicElement;
What is the reason?
Solved! Go to Solution.
Solved by ChristianBlei. Go to Solution.
Hi,
startoing in AS 2019 you need to start a transaction and access objects inside of a transaction. Before AS2019 with the calling of an Advance Steel API command implicitly a transaction was started at command start and committed at command and. That is now up to you. So use code like
Public Shared Sub GetReprType() Dim tObjId As ObjectId = UserInteraction.SelectObject If tObjId IsNot Nothing Then DocumentManager.LockCurrentDocument() Using tTrans As Transaction = TransactionManager.StartTransaction Try Dim tFilerObj As FilerObject = DatabaseManager.Open(tObjId) Dim tReprObjId As ObjectId = DatabaseManager.GetReprId(tFilerObj) Dim tAcObjId As New DatabaseServices.ObjectId(tReprObjId.AsOldId) Dim tReprName As String = tAcObjId.ObjectClass.Name Debug.Print("") MsgBox(tReprName) Catch ex As Exception Finally tTrans.Commit() End Try End Using DocumentManager.UnlockCurrentDocument() End If End Sub
By the way: If you select Acad entities with userinteraction metrhod, their ADVS ObjectId will be null.
HTH,
Hi,
startoing in AS 2019 you need to start a transaction and access objects inside of a transaction. Before AS2019 with the calling of an Advance Steel API command implicitly a transaction was started at command start and committed at command and. That is now up to you. So use code like
Public Shared Sub GetReprType() Dim tObjId As ObjectId = UserInteraction.SelectObject If tObjId IsNot Nothing Then DocumentManager.LockCurrentDocument() Using tTrans As Transaction = TransactionManager.StartTransaction Try Dim tFilerObj As FilerObject = DatabaseManager.Open(tObjId) Dim tReprObjId As ObjectId = DatabaseManager.GetReprId(tFilerObj) Dim tAcObjId As New DatabaseServices.ObjectId(tReprObjId.AsOldId) Dim tReprName As String = tAcObjId.ObjectClass.Name Debug.Print("") MsgBox(tReprName) Catch ex As Exception Finally tTrans.Commit() End Try End Using DocumentManager.UnlockCurrentDocument() End If End Sub
By the way: If you select Acad entities with userinteraction metrhod, their ADVS ObjectId will be null.
HTH,
Hi, Christian
Thanks for answer.
But as I know your code for VB.NET. My question about C#
Hi, Christian
Thanks for answer.
But as I know your code for VB.NET. My question about C#
Hi,
there are code translators, that you can find in the net that help to translate between VB and C#.
The code inC# would be like
class Test { public static void GetAtom() { ObjectId tObjId = UserInteraction.SelectObject(); if (tObjId.IsNull()== false) { DocumentManager.LockCurrentDocument(); using (Transaction tTrans = TransactionManager.StartTransaction()) { try { FilerObject tFilerObj = DatabaseManager.Open(tObjId); if (tFilerObj.IsKindOf(FilerObject.eObjectType.kAtomicElem)) { AtomicElement tAtom = (AtomicElement)tFilerObj; } } catch (Exception ex) { } finally { tTrans.Commit(); } } DocumentManager.UnlockCurrentDocument(); } } }
HTH,
Hi,
there are code translators, that you can find in the net that help to translate between VB and C#.
The code inC# would be like
class Test { public static void GetAtom() { ObjectId tObjId = UserInteraction.SelectObject(); if (tObjId.IsNull()== false) { DocumentManager.LockCurrentDocument(); using (Transaction tTrans = TransactionManager.StartTransaction()) { try { FilerObject tFilerObj = DatabaseManager.Open(tObjId); if (tFilerObj.IsKindOf(FilerObject.eObjectType.kAtomicElem)) { AtomicElement tAtom = (AtomicElement)tFilerObj; } } catch (Exception ex) { } finally { tTrans.Commit(); } } DocumentManager.UnlockCurrentDocument(); } } }
HTH,
Yeah, problem in Transaction. With transaction works good.
Yeah, problem in Transaction. With transaction works good.
Can't find what you're looking for? Ask the community or share your knowledge.