ClientGraphics Line Width

By Xiaodong Liang

Issue
The default line width is 1 pixel, but for nice highlighting it is necessary to paint the lines with at least 2 pixel width.  Can this be done by API?

Solution

The "LineGraphics" or “LineStripGraphics” provide the properties:

  • LineWeight: gets and sets the thickness of this primitive. If LineDefinitionSpace is set to kScreenSpace, this value is defined in pixels. If LineDefinitionSpace is set to kModelSpace, this value is defined in model units (centimeters).

  • LineType: gets and sets the line type associated with the primitive – LineScale: gets and sets the line scale applied to this primitive –

LineDefinitionSpace is an enum of line definition space for this primitive. It has 3 values:

Public Enum LineDefinitionSpaceEnum
    kScreenSpace = 49921
    kModelSpace = 49922
    kHybridSpace = 49923
End Enum

The code below creates the line graphics. You can change the three properties to see the effects.

static void test()            {                 // assume we have had Inventor application                     // get current document                PartDocument oCurrentDoc =                    _InvApplication.ActiveDocument as                        PartDocument;                     PartComponentDefinition oCompDef = oCurrentDoc.ComponentDefinition;                     // add ClientGraphics                ClientGraphics oClientGraphics = null;                try                {                    oClientGraphics = oCompDef.ClientGraphicsCollection["CG_Test"];                    if (oClientGraphics != null)                    {                        oClientGraphics.Delete();                    }                }                catch                { }                oClientGraphics = oCompDef.ClientGraphicsCollection.Add("CG_Test");                     //add GraphicsDataSets                GraphicsDataSets oDataSets;                try                {                    oDataSets = oCurrentDoc.GraphicsDataSetsCollection["CG_Test"];                    if (oDataSets != null)                    {                        oDataSets.Delete();                    }                }                catch                { }                     oDataSets = oCurrentDoc.GraphicsDataSetsCollection.Add("CG_Test");                            GraphicsCoordinateSet oCoordSet = oDataSets.CreateCoordinateSet(1);                     // add GraphicsNode                            GraphicsNode oLineNode = oClientGraphics.AddNode(1);                // add LineGraphics                LineGraphics oLineSet = oLineNode.AddLineGraphics();                oLineSet.CoordinateSet = oCoordSet;                     TransientGeometry oTG = _InvApplication.TransientGeometry;                     oCoordSet.Add(1, oTG.CreatePoint(0, 0, 0));                oCoordSet.Add(2, oTG.CreatePoint(6, 0, 0));                oCoordSet.Add(3, oTG.CreatePoint(6, 0, 0));                oCoordSet.Add(4, oTG.CreatePoint(6, 3, 0));                     // set LineDefinitionSpace as screen space                oLineSet.LineDefinitionSpace = LineDefinitionSpaceEnum.kScreenSpace  ;                // set lineweight                 oLineSet.LineWeight = 2;                // set LineType                oLineSet.LineType = LineTypeEnum.kDashedLineType;                // set LineScale                oLineSet.LineScale = 2;                _InvApplication.ActiveView.Update(); ;            }

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading