Hi, I'm using the COM/Interop API, through .NET to get/set PartReference Data:
string[,] partData = (string[,])bomMgr.GetPartData(vbaPartRef);
But when I update some values and want to set the PartData with
bomMgr.SetPartData(vbaPartRef, partData);
I get a COM Exception.
Any ideas?
Not a real help, but for the sake of completeness: the (generic?) error message:
Error HRESULT E_FAIL has been returned from a call to a COM component.
Error Code: -2147467259
Hi,
I have the same problem...
I can insert a part reference in the model space and I can asociate it with the bill of materials.
But i can´t change values of component properties, this line of code crash;
gBomMgr.SetPartData(gPartRef, aa);
Any idea?
Thanks,
This is the code;
<CommandMethod("Asdkcmd")> _ Public Sub Asdkcmd() Dim acadapp As Autodesk.AutoCAD.Interop.AcadApplication acadapp = CLAcApp.AcadApplication Dim acadDoc As AcadDocument = acadapp.ActiveDocument Dim symbb As McadSymbolBBMgr symbb = acadapp.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr") 'Get BOM manager Dim gBomMgr As IMcadBOMMgr gBomMgr = symbb.BOMMgr 'Create part reference Dim gPartRef As McadPartReference gPartRef = acadDoc.ModelSpace.AddCustomObject("AcmPartRef") ' Asociate part reference with BOM Dim symBOMs As McadBOMs = symbb.BOMMgr.GetAllBOMTables(True) If symBOMs IsNot Nothing AndAlso symBOMs.Count > 0 Then For Each symBOM As McadBOM In symBOMs symBOM.AddItem(gPartRef.ObjectID, CStr(symBOM.Items.Count + 1)) Exit For Next End If ' change data of part reference Dim aa(1, 1) As String aa = gBomMgr.GetPartData(gPartRef) gBomMgr.SetPartData(gPartRef, aa) End Sub
Hi,
I resolved this issue.
First I watch the columns of the part reference whith this function;
<CommandMethod("GetColumnsPartRef")> _ Public Sub GetColumnsPartRef() Dim acadapp As Autodesk.AutoCAD.Interop.AcadApplication acadapp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication Dim acadDoc As AcadDocument = acadapp.ActiveDocument Dim symbb As McadSymbolBBMgr symbb = acadapp.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr") 'Get BOM manager Dim gBomMgr As IMcadBOMMgr gBomMgr = symbb.BOMMgr 'Get standard manager Dim stdMgr As McadStandardMgr stdMgr = symbb.StandardMgr 'Get the current standard Dim currentStd As McadStandard currentStd = stdMgr.CurrentStandard 'Get BOM Standard Dim BOMStd As McadBOMStandard BOMStd = currentStd.BOMStandard 'Get all BOM visible columns from BOM standard Dim BOMcol As McadColumnDefinitions BOMcol = BOMStd.Columns For i As Integer = 0 To BOMStd.Columns.Count - 1 MsgBox(i + 1 & ". COLUMN NAME -> " & BOMStd.Columns.Item(i).Name & vbLf & _ i + 1 & ". COLUMN CAPTION -> " & BOMStd.Columns.Item(i).Caption) Next End Sub
This command helps me to get the columns names that I want to change. In my case the columns are "STANDARD", "DESCR" and "MATERIAL".
Finally, I change my code;
<CommandMethod("InsertPartReference")> _ Public Sub InsertPartReference() Dim acadapp As Autodesk.AutoCAD.Interop.AcadApplication acadapp = CLAcApp.AcadApplication Dim acadDoc As AcadDocument = acadapp.ActiveDocument Dim symbb As McadSymbolBBMgr symbb = acadapp.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr") 'Get BOM manager Dim gBomMgr As IMcadBOMMgr gBomMgr = symbb.BOMMgr 'Create part reference Dim gPartRef As McadPartReference gPartRef = acadDoc.ModelSpace.AddCustomObject("AcmPartRef") Dim point(2) As Double : point(0) = 0.0 : point(1) = 100.0 : point(2) = 0.0 gPartRef.Origin = point ' Asociate part reference with BOM Dim symBOMs As McadBOMs = symbb.BOMMgr.GetAllBOMTables(True) If symBOMs IsNot Nothing AndAlso symBOMs.Count > 0 Then For Each symBOM As McadBOM In symBOMs symBOM.AddItem(gPartRef.ObjectID, CStr(symBOM.Items.Count + 1)) Exit For Next End If ' change data of part reference Dim matData(0 To 2, 0 To 1) As String matData(0, 0) = "STANDARD" matData(0, 1) = "standar" matData(1, 0) = "DESCR" matData(1, 1) = "descr" matData(2, 0) = "MATERIAL" matData(2, 1) = "material" gBomMgr.SetPartData(gPartRef, matData) gPartRef.Update() gPartRef.UpdateToAttachedObject() End Sub
Now, the code don´t crash.