Advance Steel Forum
Welcome to Autodesk’s Advance Steel Forums. Share your knowledge, ask questions, and explore popular Advance Steel topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Advance Steel 2019 API Selection method

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
NinovSM
964 Views, 4 Replies

Advance Steel 2019 API Selection method

NinovSM
Advocate
Advocate

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?

0 Likes

Advance Steel 2019 API Selection method

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?

4 REPLIES 4
Message 2 of 5
ChristianBlei
in reply to: NinovSM

ChristianBlei
Advisor
Advisor

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,

 

 

 

 

Christian Blei
CBT Christian Blei Tools
christianblei.de
youtube.com/channel/UCxjA_NbeScQy9C0Z1xjwXpw
0 Likes

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,

 

 

 

 

Christian Blei
CBT Christian Blei Tools
christianblei.de
youtube.com/channel/UCxjA_NbeScQy9C0Z1xjwXpw
Message 3 of 5
NinovSM
in reply to: ChristianBlei

NinovSM
Advocate
Advocate

Hi, Christian

Thanks for answer.

But as I know your code for VB.NET. My question about C#

0 Likes

Hi, Christian

Thanks for answer.

But as I know your code for VB.NET. My question about C#

Message 4 of 5
ChristianBlei
in reply to: NinovSM

ChristianBlei
Advisor
Advisor
Accepted solution

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,

 

 

Christian Blei
CBT Christian Blei Tools
christianblei.de
youtube.com/channel/UCxjA_NbeScQy9C0Z1xjwXpw
 

 

Christian Blei
CBT Christian Blei Tools
christianblei.de
youtube.com/channel/UCxjA_NbeScQy9C0Z1xjwXpw
0 Likes

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,

 

 

Christian Blei
CBT Christian Blei Tools
christianblei.de
youtube.com/channel/UCxjA_NbeScQy9C0Z1xjwXpw
 

 

Christian Blei
CBT Christian Blei Tools
christianblei.de
youtube.com/channel/UCxjA_NbeScQy9C0Z1xjwXpw
Message 5 of 5
NinovSM
in reply to: ChristianBlei

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report