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!
Solved! Go to Solution.
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!
Solved! Go to Solution.
Solved by ChristianBlei. Go to 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,
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,
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!
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!
Can't find what you're looking for? Ask the community or share your knowledge.