- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello!
I have a problem to create a linear dimension by workpoints made on parts. My code is running perfectly when I have one level subassembly. I use occurence and suboccurence to get the part and workpoints. From workpoints I create proxies, then centermarks and geometry intent which is needed for creating dimensions.
But when I need to go deeper into subassembly/subassembly/part to get the workpoint for dimension I get an error. Actually I get the correct part (Checked with MessageBox.Show("Part Name") and MessageBox.Show("Workpoint")), but when I want to "SetInclude" proxies of these points I get an error?
The code below is running OK when I want to work with adapter parts but I need corner parts:
public void MakeAssemblyDrawingDimensionOnFirstAssemblyLevel(AssemblyDocument oAssyDoc, Sheet oSheet, DrawingView oView, int compOcc1, int compSubOcc1, int compOcc2, int compSubOcc2, string WP1, string WP2)
{
GeneralDimensions oGD;
GeneralDimension oDim;
ComponentOccurrence oOc1;
ComponentOccurrence oOc2;
PartComponentDefinition oOc1PD;
PartComponentDefinition oOc2PD;
WorkPoint oWP1;
WorkPoint oWP2;
WorkPointProxy oWPp1;
WorkPointProxy oWPp2;
Centermarks oCM;
Centermark oC1;
Centermark oC2;
GeometryIntent oIntent1;
GeometryIntent oIntent2;
Point2d oPos;
TransientGeometry oTG;
oGD = oSheet.DrawingDimensions.GeneralDimensions;
oTG = m_inventorApplication.TransientGeometry;
oOc1 = oAssyDoc.ComponentDefinition.Occurrences[compOcc1].SubOccurrences[compSubOcc1];
oOc1PD = (PartComponentDefinition)oOc1.Definition;
oWP1 = oOc1PD.WorkPoints[WP1];
oOc2 = oAssyDoc.ComponentDefinition.Occurrences[compOcc2].SubOccurrences[compSubOcc2];
oOc2PD = (PartComponentDefinition)oOc2.Definition;
oWP2 = oOc2PD.WorkPoints[WP2];
Object oPoint = null;
oOc1.CreateGeometryProxy(oWP1, out oPoint);
oWPp1 = (WorkPointProxy)oPoint;
oOc2.CreateGeometryProxy(oWP2, out oPoint);
oWPp2 = (WorkPointProxy)oPoint;
oView.SetIncludeStatus(oWPp1, true);
oView.SetIncludeStatus(oWPp2, true);
oCM = oSheet.Centermarks;
int n = oCM.Count;
oC1 = oCM[n];
oC2 = oCM[n - 1];
oIntent1 = oSheet.CreateGeometryIntent(oC1);
oIntent2 = oSheet.CreateGeometryIntent(oC2);
oPos = oTG.CreatePoint2d((oC1.Position.X - oC2.Position.X) / 2 + oC2.Position.X, oC1.Position.Y - 1);
oDim = (GeneralDimension)oGD.AddLinear(oPos, oIntent1, oIntent2, DimensionTypeEnum.kHorizontalDimensionType);
}
My idea was to drop down main AssemblyDocument object to lower Assembly occurence and make it new "main assembly" from which I can get its parts as suboccurence:
AssemblyDocument oAssy; //main assembly
ComponentOccurrence oOc1 = oAssy.ComponentDefinition.Occurrences[2]; //subassembly Box1
AssemblyComponentDefinition oAsmCompDef = (AssemblyComponentDefinition)oOc1.Definition;
ComponentOccurrence oOc2 = oAsmCompDef .Occurrences[2].SubOccurrences[1]; //subass. Box_1 Frame ,part Corner:1
PartComponentDefinition oOc2PD = (PartComponentDefinition)oOc2.Definition;
WorkPoint oWP1 = oOc2PD.WorkPoints[WP1]; //point from Corner:1
Solved! Go to Solution.