Hello,
I'm writing a little c# tool, where a user can mark sketch points in PlanarSketches and SketchBlockDefinitions.
The points will be marked by attributes and actually represent the bounding box of the profile for CAM processing.
While my command is active, the location and description of the points should be visible to the user, upon end of the command this info should be invisble again.
So, when the user has selected a SketchPoint, I will write a text description of the point (f.e. Origin, MaxX, MaxY, MaxXY) next to it using ClientGraphics/TextGraphics.
This works fine, as long as the user selects Points inside a PlanarSketch, but when the user edits a SketchBlockDefinition, the TextGraphics can not be seen.
here is a small example of my code:
void createClientGfx()
{
ComponentDefinition compDef = null;
Inventor.Document doc = m_inventorApplication.ActiveDocument;
if (m_inventorApplication.ActiveDocument is PartDocument)
{
compDef = (ComponentDefinition)((PartDocument)m_inventorApplication.ActiveDocument).ComponentDefinition;
}
else if (m_inventorApplication.ActiveDocument is AssemblyDocument)
{
compDef = (ComponentDefinition)((AssemblyDocument)m_inventorApplication.ActiveDocument).ComponentDefinition;
}
try
{
m_clientGraphics = compDef.ClientGraphicsCollection[CAMP_POS_GFX];
}
catch (System.Exception) { }
if (m_clientGraphics == null)
{
m_clientGraphics = compDef.ClientGraphicsCollection.Add(CAMP_POS_GFX);
}
m_node = m_clientGraphics.AddNode(1);
}
TextGraphics addtextGfx(string strText, Point2d position)
{
TextGraphics textGfx1 = m_node.AddTextGraphics();
textGfx1.Text = strText;
textGfx1.Anchor = m_inventorApplication.TransientGeometry.CreatePoint(position.X + OFFSET, position.Y, 0.0);
textGfx1.Font = "Arial";
textGfx1.FontSize = 20;
textGfx1.HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft;
textGfx1.Italic = false;
textGfx1.PutTextColor(255,255,0);
//textGfx1.VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextBaseline;
//Call oTextGraphics(3).SetTransformBehavior(oModelAnchorPoint, kFrontFacingAndPixelScaling)
m_inventorApplication.ActiveView.Update();
return textGfx1;
}
Any help, why the code isn't working in SketchBlockDefinitions would be appreciated.
regards
Ludger
Hi Ludger,
Which version of Inventor are you using? Under 2014 I don't reproduce that behavior. Here is my workflow:
- Create a sketchblock and exit from the sketch
- Double click the sketch in Inventor browser to activate the definition
- Run following VBA:
Sub TestProcGraphics() Dim doc As Document Set doc = ThisApplication.ActiveDocument Dim Tg As TransientGeometry Set Tg = ThisApplication.TransientGeometry Dim compDef As ComponentDefinition Set compDef = doc.ComponentDefinition On Error Resume Next Dim dataSets As GraphicsDataSets Set dataSets = doc.GraphicsDataSetsCollection.Add("TestCG") If Err Then Set dataSets = doc.GraphicsDataSetsCollection("TestCG") End If Dim cg As clientGraphics Set cg = compDef.ClientGraphicsCollection.Add("TestCG") If Err Then Set cg = compDef.ClientGraphicsCollection("TestCG") End If Call TextClientGraphics( _ dataSets, cg, _ Tg.CreatePoint(0, 0, 0), _ "Client Graphics Text") ThisApplication.ActiveView.Update End Sub Sub TextClientGraphics( _ dataSets As GraphicsDataSets, _ cg As clientGraphics, _ position As point, _ text As String) Dim node As GraphicsNode Set node = cg.AddNode(cg.count + 1) 'Rotate node Dim Matrix As Matrix Set Matrix = ThisApplication.TransientGeometry.CreateMatrix Call Matrix.SetTranslation( _ ThisApplication.TransientGeometry.CreateVector(10, 5, 5)) Dim axe As vector Set axe = ThisApplication.TransientGeometry.CreateVector(1, 0, 0) Call Matrix.SetToRotation(4 * Atn(1) / 2, axe, position) node.Transformation = Matrix Dim Tg As TextGraphics Set Tg = node.AddTextGraphics 'Set the properties of the text Tg.DepthPriority = 0 Tg.text = text Tg.Anchor = position Tg.Bold = True Tg.Font = "Arial" Tg.FontSize = 40 Tg.HorizontalAlignment = kAlignTextCenter Tg.Italic = True Call Tg.PutTextColor(0, 255, 0) Tg.VerticalAlignment = kAlignTextMiddle Tg.RemoveViewSpaceAnchor End Sub
Philippe.
Hi Philippe,
thank you for your reply.
I am using Inventor 2012.
I have modified your example, so it prints the SketchpointNumber of the first 10 SketchPoints, and it works fine!
But I have still to find out why my c# code would run fine for PlanarSketches and doesn't display anything for SketchBlockDefs...
For i = 1 To 10
Dim oPoint As SketchPoint
Set oPoint = oBlockDef.SketchPoints(i)
Call TextClientGraphics( _
dataSets, cg, _
Tg.CreatePoint(oPoint.Geometry.X, oPoint.Geometry.Y, 0), _
"Pt_" & i)
ThisApplication.ActiveView.Update
Next i
best regards
Ludger
Can't find what you're looking for? Ask the community or share your knowledge.