cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Create a dimension in a drawing view between a CSYS and the axis of a hole

JAZOZevenaarbv
7-Bedrock

Create a dimension in a drawing view between a CSYS and the axis of a hole

My goal is to create a dimension in a drawing view between a CSYS and the axis of a hole. This dimension will then be converted to ordinate, together with dimension of other holes.

 

I'm able to add the axis to the selection but the command Drawing.CreateDimension throws the exception XToolkitBadDimAttach.

 

This is what I have so far:

 

public void createAxisDims() throws com.ptc.cipjava.jxthrowable
{
session.UIClearMessage();


if (model.GetType() != ModelType.MDL_DRAWING) {
return;
}
Dimension hBaseline = null;
Dimension vBaseline = null;

Drawing drawing = (Drawing)model;
View2D selView = drawing.GetViewByName("VOORAANZICHT");

Solid rootSolid = (Solid)selView.GetModel();

ModelItem csys = rootSolid.GetItemByName(ModelItemType.ITEM_COORD_SYS, "CS_INSTALL_DIM");

Selection csysSel = pfcSelect.CreateModelItemSelection (csys, null);

csysSel.Highlight(StdColor.COLOR_EDGE_HIGHLIGHT);
ModelItem selItem = csysSel.GetSelItem();

ComponentPath selPath = csysSel.GetPath();
Point3D selPos = csysSel.GetPoint();

Transform3D asmTransf = null;

if (selPath != null)
{
rootSolid = (Solid)selPath.GetRoot();
asmTransf = selPath.GetTransform(true);
}

ArrayList<ModelItem> axes = findAxis(rootSolid);

if (axes == null || axes.size() == 0)
return;

Point3D csysPos = selPos;
if (asmTransf != null)
{
csysPos = asmTransf.TransformPoint (selPos);
}
Transform3D viewTransf = selView.GetTransform();
csysPos = viewTransf.TransformPoint (csysPos);

Vector2D csys3DPos = Vector2D.create ();
csys3DPos.set (0, csysPos.get (1));
csys3DPos.set (1, csysPos.get (0));

Outline3D outline = selView.GetOutline();

DimSenses senses = DimSenses.create();
DimensionAttachments attachments = DimensionAttachments.create();

for(int p=0; p<axes.size(); p++)
{

try {
Axis axis = (Axis)axes.get(p);

Selection pntSel = pfcSelect.CreateModelItemSelection (axis, null);

pntSel.Highlight(StdColor.COLOR_EDGE_HIGHLIGHT);

Point3D pntPos = pntSel.GetPoint ();
pntPos = viewTransf.TransformPoint (pntPos);

PointDimSense sense1 =
pfcDimension.PointDimSense_Create (DimPointType.DIMENSION_POINT_NONE);
senses.set (0, sense1);
PointDimSense sense2 =
pfcDimension.PointDimSense_Create (DimPointType.DIMENSION_POINT_CENTER);
senses.set (1, sense2);

DimensionAttachment attach1 = DimensionAttachment.create();
DimensionAttachment attach2 = DimensionAttachment.create();


pntSel.SetSelView2D(selView);
attach1.set (0, pntSel);
attach2.set (0, csysSel);

attachments.set(0,attach1);
attachments.set(1,attach2);

Point2D dimPos = Point2D.create ();
dimPos.set (0, outline.get (0).get (0) - 20.0);
dimPos.set (1, (csysPos.get (1) + pntPos.get (1))/2.0);

Dimension dim = drawing.CreateDimension (attachments,senses,DimOrientationHint.ORIENTATION_HINT_SLANTED,dimPos);

DrawingDimensionShowInstructions showInstrs =
pfcView2D.DrawingDimensionShowInstructions_Create (selView, null);

dim.Show (showInstrs);

if(p==0)
{
vBaseline = drawing.ConvertLinearDimensionToBaseline(dim, csys3DPos);
}

else
drawing.ConvertLinearDimensionToOrdinate(dim, vBaseline);

} catch (Exception e) {
texts = stringseq.create();
texts.set(0, "createAxisDims for dim " + String.valueOf(p));
texts.set(1, e.toString());
session.UIDisplayMessage(Settings.MSGFILE, "USER GeneralException", texts);
}
}
}

0 REPLIES 0
Announcements


Top Tags