So I have a series of large projects here, and I'm trying to build a template for it. As part of this template I've got a series of iParts which go together to make iAssemblies (there's potentially a couple hundred instances of each iAssembly in each one of these projects, and up to 25 different versions. Because there's up to 25 different versions of the assembly, there's also up to 25 different versions of each iPart which goes into the assembly.
The top-level assembly will have a form which outputs values to the excel spreadsheet, and the goal here is for each sub-iAssembly and iPart to draw values from that table to fill in their own author tables.
I'm having a hard time right now figuring out how to draw the data from Excel into the iPart / iAssembly tables. I can get the information from Excel and set parameters with it, but I haven't figured out how to use it to populate the iPart / iAssembly table.
Anyone got any suggestions?
Rusty
Hi,
If you can reach data from excel and want to put them in iPart table you can do that through PartDocument.ComponentDefinition.iPartFactory.CreateMember(Row)
Regards,
Nedeljko.
I don't think the suggestion from Nedeljko will help here, CreateMember will just generate a member file corresponding to the specified row, which is not what you are looking for if I understand correctly the question.
You need to edit programmatically the iPart table, which is not doable directly from the available API but you can do it by editing the embedded Excel document that defines the table.
Below are VBA examples that illustrates how to dump content of the table and create a basic iPart from scratch. What you need to do is to edit a row of the table as you would wish from the UI and observe the syntax, so you can reproduce it from API:
Public Sub DumpiPartTable() Dim doc As PartDocument Set doc = ThisApplication.ActiveDocument If (Not doc.ComponentDefinition.IsiPartFactory) Then Exit Sub Dim factory As iPartFactory Set factory = doc.ComponentDefinition.iPartFactory Dim ws As Variant 'WorkSheet Set ws = factory.ExcelWorkSheet Dim rowIdx As Integer Dim colIdx As Integer For rowIdx = 1 To factory.TableRows.count + 1 Debug.Print "-------------------------------------------------" For colIdx = 1 To factory.TableColumns.count Debug.Print "Cell[" & rowIdx & "," & colIdx & "]: " & _
ws.Cells(rowIdx, colIdx).text Next Next End Sub Public Sub DumpiAssemblyTable() Dim doc As AssemblyDocument Set doc = ThisApplication.ActiveDocument If (Not doc.ComponentDefinition.IsiAssemblyFactory) Then Exit Sub End If Dim factory As iAssemblyFactory Set factory = doc.ComponentDefinition.iAssemblyFactory Dim ws As Variant ' WorkSheet Set ws = factory.ExcelWorkSheet Dim rowIdx As Integer Dim colIdx As Integer For rowIdx = 1 To factory.TableRows.count + 1 Debug.Print "-------------------------------------------------" For colIdx = 1 To factory.TableColumns.count Debug.Print "Cell[" & rowIdx & "," & colIdx & "]: " & _
ws.Cells(rowIdx, colIdx).text Next Next End Sub Public Sub CreateiPart() Dim oPartDoc As PartDocument Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _ ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject), _ True) oPartDoc.SaveAs "c:\Temp\APIiPart.ipt", False Dim oTG As TransientGeometry Set oTG = ThisApplication.TransientGeometry Dim oCompDef As PartComponentDefinition Set oCompDef = oPartDoc.ComponentDefinition Dim oPoints(3) As point2d Set oPoints(0) = oTG.CreatePoint2d(0, 0) Set oPoints(1) = oTG.CreatePoint2d(5, 0) Set oPoints(2) = oTG.CreatePoint2d(5, 5) Set oPoints(3) = oTG.CreatePoint2d(0, 5) Dim oSketch As PlanarSketch Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(1)) Dim oLines(3) As SketchLine Set oLines(0) = oSketch.SketchLines.AddByTwoPoints( _
oPoints(0), oPoints(1))
Set oLines(1) = oSketch.SketchLines.AddByTwoPoints( _
oLines(0).EndSketchPoint, oPoints(2))
Set oLines(2) = oSketch.SketchLines.AddByTwoPoints( _
oLines(1).EndSketchPoint, oPoints(3))
Set oLines(3) = oSketch.SketchLines.AddByTwoPoints( _
oLines(2).EndSketchPoint, oLines(0).StartSketchPoint) Dim oProfile As profile Set oProfile = oSketch.Profiles.AddForSolid Dim oExtrude As ExtrudeFeature Set oExtrude = _
oCompDef.features.ExtrudeFeatures.AddByDistanceExtent( _
oProfile, 15, kPositiveExtentDirection, kNewBodyOperation, 0) oExtrude.FeatureDimensions(1).parameter.Name = "Length" oExtrude.FeatureDimensions(2).parameter.Name = "TaperAngle" Dim oFactory As iPartFactory Set oFactory = oCompDef.CreateFactory Dim oWS As WorkSheet Set oWS = oFactory.ExcelWorkSheet oWS.Cells(1, 1) = "Member<defaultRow>1</defaultRow><filename></filename>" oWS.Cells(1, 2) = "Part Number [Project]" oWS.Cells(1, 3) = "Length<free>150 mm</free>" oWS.Cells(1, 4) = "TaperAngle" oWS.Cells(2, 1) = "APIiPart-01" oWS.Cells(2, 2) = "APIiPart-01" oWS.Cells(2, 3) = "150 mm" oWS.Cells(2, 4) = "0 deg" oWS.Cells(3, 1) = "APIiPart-02" oWS.Cells(3, 2) = "APIiPart-02" oWS.Cells(3, 3) = "100 mm" oWS.Cells(3, 4) = "5 deg" oWS.Cells(4, 1) = "APIiPart-03" oWS.Cells(4, 2) = "APIiPart-03" oWS.Cells(4, 3) = "50 mm" oWS.Cells(4, 4) = "10 deg" Dim oWB As workbook Set oWB = oWS.Parent oWB.Save oWB.Close oPartDoc.Update oPartDoc.Save End Sub
Take care not to mess up with the table as you could corrupt the document.
Hope that helps,
Philippe.
______________________________________________________________
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
Wow. That's ... a little more complicated than what I was expecting / hoping, to be perfectly honest.
I can pre-create all ~25 rows in my template file no problem. I just need to edit the data that exists in the table. There's no way to do it without getting into the API?
If not, that's okay too ... If I've already got to take a dip in the iLogic pool, I might as well go all the way off the deep end and find an excuse to learn the whole API thing too. 🙂
Rusty
I don't think iLogic can do it, but it supports direct Vb.Net syntax in a rule, so you could pretty much cut and paste that code in a rule. To make it work you would need to migrate the syntax to Vb.Net, which is rather straightforward:
http://msdn.microsoft.com/en-us/library/office/aa192490%28v=office.11%29.aspx
It's actually not so complicated than it may look, that's just a matter of accessing the Excel document and edit the values. The API itself for iPart isn't very powerful in terms of manipulating the iPart table, editing through Excel is the only to achieve table modifications.
The API being much more powerful and flexible than iLogic, I think it would be a good investment if you want to get started with it, we have multiple resources to help you with:
http://www.autodesk.com/developinventor
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=17324828
https://github.com/ADN-DevTech/Inventor-Training-Material
Feel free to report your progress.
Good luck,
Philippe.
dear sir
it has been 4 years since the topic was opened and im having trouble with smiliar situation
i got an ipart that have 20 diffrent variations and each variation is used in a sub assambley, i figured to calculate the dimentions inside excel infact i have to enter just 3 inputs to excel formula so i need to change a specific shell in excel from a rule nested inside top level assambley or maybe just a code set to open ipart excel spreadsheet from top level assambley, but pls less user interract
i dont wanna be a lazy student thats why i will try to figure my way through API but time is essance could you pls light my way out ?