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: 

API - can't get FilerObject

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
m.shemur
568 Views, 2 Replies

API - can't get FilerObject

m.shemur
Contributor
Contributor

Hello!

Here I use AS 2018

What is my task - I make DataGrid with bolts using C#

I filled it by Datatable using this code. I also add the same time this bolt to a Dictionary

 

                                table.Rows.Add(bolts.Handle, bolts.ScrewDiameter, bolts.ScrewLength, list_Connected_Objects.Count() - 1);
                                boltsDict.Add(bolts.Handle, bolts.GetObjectId());

Than, I want to be able to select bolts from table by selecting a row

 

I made event for clicking

 

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex>=0)
            {
                selectBolts(e.RowIndex, table);
            }
        }

And I selectd bolts using a dictionary by comparing Handle from DataGrid (key) and ObjectID (Value)

 

 

  public void selectBolts(int i, DataTable table)
        {
            string boltHandle = table.Rows[i]["Handle"].ToString();
            ObjectId objectobject=boltsDict[boltHandle];
             //try to get FilerObject, it also fails
            FilerObject filerobj = FilerObject.GetFilerObject(objectobject);
           //operations to mark bolt
            List<Autodesk.AutoCAD.DatabaseServices.ObjectId> ACobj = new List<Autodesk.AutoCAD.DatabaseServices.ObjectId>();
           //problem string:
ObjectId boltObjID = DatabaseManager.GetReprId(DatabaseManager.Open(objectobject)); Utils.SelectObjects(ACobj.ToArray()); ed.Command(new object[] { "._AstM4CommMarkSelAdd" }); }

The problem is that a get a mistake when I click on a row

System.NullReferenceException: 

 in Autodesk.AdvanceSteel.CADAccess.DatabaseManager.GetReprId(FilerObject obj)

Mistake is here

            ObjectId boltObjID = DatabaseManager.GetReprId(DatabaseManager.Open(objectobject));

I also can't get FilerObject by simple

            FilerObject filerobj = FilerObject.GetFilerObject(objectobject);

as I wrote in code before. So it comes that problem is exactly here.

It returns filerobj=null  even objectobject has a value of ObjectID

Before, I didn't use dictionary - I got ObjectID from Handle and it also didn't work

 

Would appreciate any help

 

Thank you!

 

 

 

 

0 Likes

API - can't get FilerObject

Hello!

Here I use AS 2018

What is my task - I make DataGrid with bolts using C#

I filled it by Datatable using this code. I also add the same time this bolt to a Dictionary

 

                                table.Rows.Add(bolts.Handle, bolts.ScrewDiameter, bolts.ScrewLength, list_Connected_Objects.Count() - 1);
                                boltsDict.Add(bolts.Handle, bolts.GetObjectId());

Than, I want to be able to select bolts from table by selecting a row

 

I made event for clicking

 

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex>=0)
            {
                selectBolts(e.RowIndex, table);
            }
        }

And I selectd bolts using a dictionary by comparing Handle from DataGrid (key) and ObjectID (Value)

 

 

  public void selectBolts(int i, DataTable table)
        {
            string boltHandle = table.Rows[i]["Handle"].ToString();
            ObjectId objectobject=boltsDict[boltHandle];
             //try to get FilerObject, it also fails
            FilerObject filerobj = FilerObject.GetFilerObject(objectobject);
           //operations to mark bolt
            List<Autodesk.AutoCAD.DatabaseServices.ObjectId> ACobj = new List<Autodesk.AutoCAD.DatabaseServices.ObjectId>();
           //problem string:
ObjectId boltObjID = DatabaseManager.GetReprId(DatabaseManager.Open(objectobject)); Utils.SelectObjects(ACobj.ToArray()); ed.Command(new object[] { "._AstM4CommMarkSelAdd" }); }

The problem is that a get a mistake when I click on a row

System.NullReferenceException: 

 in Autodesk.AdvanceSteel.CADAccess.DatabaseManager.GetReprId(FilerObject obj)

Mistake is here

            ObjectId boltObjID = DatabaseManager.GetReprId(DatabaseManager.Open(objectobject));

I also can't get FilerObject by simple

            FilerObject filerobj = FilerObject.GetFilerObject(objectobject);

as I wrote in code before. So it comes that problem is exactly here.

It returns filerobj=null  even objectobject has a value of ObjectID

Before, I didn't use dictionary - I got ObjectID from Handle and it also didn't work

 

Would appreciate any help

 

Thank you!

 

 

 

 

2 REPLIES 2
Message 2 of 3
ChristianBlei
in reply to: m.shemur

ChristianBlei
Advisor
Advisor
Accepted solution

Hi,

 

Use the Databasemanager.Open code inside of a transaction, like in VB.net

Also check if you have to use the Bolts.GetObjId inside of a transaction

 

        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()

 

HTH,

 

 

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

Hi,

 

Use the Databasemanager.Open code inside of a transaction, like in VB.net

Also check if you have to use the Bolts.GetObjId inside of a transaction

 

        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()

 

HTH,

 

 

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

m.shemur
Contributor
Contributor

Thank you! Everything works fine now!

One more question I have...

Once you mentioned that

first:

I recommend that you change to AS 2019  (or at least 2018). They allow edit and continue, so they allow to  debug and edit your code at the same time. It is much more fun than using As 2017

 

But I didn't succeed in it - I just can debug it and see what happens in my code while execution in AS by attaching it to process in Debug menu, but if I change something in code - command in AS doesnt work  anymore and I cannot rebuild dll because its busy(( so I wonder how you do it 

Thank you!

0 Likes

Thank you! Everything works fine now!

One more question I have...

Once you mentioned that

first:

I recommend that you change to AS 2019  (or at least 2018). They allow edit and continue, so they allow to  debug and edit your code at the same time. It is much more fun than using As 2017

 

But I didn't succeed in it - I just can debug it and see what happens in my code while execution in AS by attaching it to process in Debug menu, but if I change something in code - command in AS doesnt work  anymore and I cannot rebuild dll because its busy(( so I wonder how you do it 

Thank you!

Tags (1)

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

Post to forums  

Autodesk Design & Make Report