Message 1 of 2
Get DrawingCurves from occurrence (C#)
Not applicable
12-26-2012
07:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In a drawing I'm looking for components that have a certain iProperty. If they have the iProperty, I want to turn every occurrence of that item red.
I can get the occurrences fine, but I'm unable to properly get the drawing curves so I can turn them red. I'm using code from this post on ModTheMachine: http://modthemachine.typepad.com/my_weblog/2010/10/changing-drawing-curves-to-match-assembly-color.h...
Here's my code:
private static void ProcessAssemblyColor(DrawingDocument aDoc, ComponentOccurrences occurrences)
{
foreach (ComponentOccurrence occ in occurrences)
{
if (occ.DefinitionDocumentType == DocumentTypeEnum.kPartDocumentObject)
{
TransientObjects transObjects = StandardAddInServer._mInventorApplication.TransientObjects;
LayersEnumerator layers = aDoc.StylesManager.Layers;
Layer colorLayer = layers[1];
colorLayer.Color = transObjects.CreateColor(255, 0, 0); //red
colorLayer.LineType = LineTypeEnum.kContinuousLineType;
colorLayer.LineWeight = 0.02;
ObjectCollection objColl = transObjects.CreateObjectCollection();
foreach (DrawingView drawView in aDoc.ActiveSheet.DrawingViews)
{
DrawingCurvesEnumerator drawingCurves = drawView.DrawingCurves[occ]; //This line throws invalid Args error
foreach (DrawingCurve drawingCurve in drawingCurves)
{
foreach (DrawingCurveSegment segment in drawingCurve.Segments)
{
objColl.Add(segment);
}
}
aDoc.ActiveSheet.ChangeLayer(objColl, colorLayer);
}
}
else
{
ProcessAssemblyColor(aDoc, (ComponentOccurrences)occ.SubOccurrences);
}
}
}
I've seen some things say I need to use an out object to use DrawingCurves. If that's true, I'm not sure what to put for the first variable.
object outObject; DrawingCurvesEnumerator drawingCurves = drawView.DrawingCurves[occ.CreateGeometryProxy(whatgoeshere?, out outObject)];
I'm open to other methods of turning components red in a drawing, but this is what appeared tio be the suggested method.