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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

C++ Toolkit - Get ProView Points/Vertexes

MarcoTeixeira
10-Marble

C++ Toolkit - Get ProView Points/Vertexes

Hello everyone.

I trying to put some dimensions automatically on a 2D drawing. I don't want that this dimensions cames from the 3D Model. I want to create directly on the drawing.

For that, i need to know some entities of the drawing, so i can give the attachments to the function ProDrawingDimCreate().

I need to know if you guys, know some way to visit entities like ProPoints or ProEdges of a specific ProView.

What do you suggest?


Many Thanks.

2 REPLIES 2

I did a similar project years ago. It was a CAD/CAM automation system written in ToolKit and API (in C#).  

Auto-dimension was included for the key feature location, implemented in C#. 

Here is My some samples code in C#. 

Hope this help

 

public bool CreateAxisPosiontDimension(TaskData task,string CsysName, string ViewName, string ParamName, string ParamValue,double PlateWidth)
{
IpfcSelection csysSelection,PointSelection;
IpfcModelItem item;
IpfcView2D selView=null;
IpfcView2Ds views;
CpfcPoint3D SelPosition;
IpfcModelItems Points;
CpfcPoint3D csysPosition,pointPisition;
IpfcTransform3D viewTransform;
CpfcVector2D Csys3DPosition,dimPosition;
IpfcOutline3D outline;
CpfcDimensionSenses senses;
IpfcPointDimensionSense sense1,sense2;
CpfcSelections attachments;
IpfcDrawingDimCreateInstructions createInstructions;
IpfcDrawingDimensionShowInstructions showInstructions;
IpfcDimension2D dimension;
IpfcDimension2D hBaseLine=null,vBaseLine=null ;
List<CpfcPoint3D> AllPoints = new List<CpfcPoint3D>();
List<IpfcModelItem> AllValidAxis= new List<IpfcModelItem>();
Mylog.AddLog("Start to Generate Position Dimension:");
try
{
drawingMdl = task.drawingModel;
OpenDrawing();
((IpfcSheetOwner)drawing).CurrentSheetNumber = 1;

item = ((IpfcModelItemOwner)task.referenceModel ).GetItemByName((int)EpfcModelItemType.EpfcITEM_COORD_SYS, CsysName);
views = ((IpfcModel2D)drawing).List2DViews();
for (int i = 0; i < views.Count; i++)
{
if (views[i].Name == ViewName)
{
selView = views[i];
break;
}
}
if (selView == null)
{
Mylog.AddLog("Can't Find View with name of " + ViewName);
return false;
}
double scale=selView.Scale;
selView.Scale = (24.0 / PlateWidth) * scale;


csysSelection = (new CMpfcSelect()).CreateModelItemSelection(item, null);
csysSelection.set_SelView2D(selView);
SelPosition = csysSelection.Point;
csysPosition = SelPosition;
viewTransform = selView.GetTransform();
csysPosition = viewTransform.TransformPoint(csysPosition);
Csys3DPosition = new CpfcVector2D();
Csys3DPosition.Set(0, csysPosition[0]);
Csys3DPosition.Set(1, csysPosition[1]);
outline = selView.Outline;
senses = new CpfcDimensionSenses();
attachments = new CpfcSelections();
sense1 = (new CCpfcPointDimensionSense()).Create((int)EpfcDimensionPointType.EpfcDIMPOINT_CENTER);
sense2 = (new CCpfcPointDimensionSense()).Create((int)EpfcDimensionPointType.EpfcDIMPOINT_CENTER);
senses.Set(0, sense1);
senses.Set(1, sense2);

Points = ((IpfcModelItemOwner)task.referenceModel ).ListItems((int)EpfcModelItemType.EpfcITEM_POINT);
for (int c = 0; c < Points.Count; c++)
{
PointSelection = (new CMpfcSelect()).CreateModelItemSelection(Points[c] , null);
PointSelection.set_SelView2D(selView);
pointPisition = viewTransform.TransformPoint(((IpfcPoint)Points[c]).Point);

attachments.Set(0, PointSelection);
attachments.Set(1, csysSelection);

dimPosition = new CpfcVector2D();

if(csysPosition[0]>pointPisition[0])
dimPosition.Set(0, outline[0][0] - 10);
else
dimPosition.Set(0, outline[1][0] + 10);
dimPosition.Set(1, (csysPosition[1] + pointPisition[1]) / 2);

createInstructions = (new CCpfcDrawingDimCreateInstructions()).Create(attachments, senses, dimPosition, (int)EpfcOrientationHint.EpfcORIENTHINT_VERTICAL);
dimension = ((IpfcModel2D)drawing).CreateDrawingDimension(createInstructions);
showInstructions = ((new CCpfcDrawingDimensionShowInstructions()).Create(selView, null));
((IpfcBaseDimension)dimension).Show(showInstructions);
if (c == 0)
{
vBaseLine = dimension.ConvertToBaseline(Csys3DPosition);
}
else
dimension.ConvertToOrdinate(vBaseLine);

createInstructions.OrientationHint = (int)EpfcOrientationHint.EpfcORIENTHINT_HORIZONTAL;

dimPosition.Set(0, (csysPosition[0] + pointPisition[0]) / 2);
if (csysPosition[1] < pointPisition[1])
dimPosition.Set(1, outline[1][1] +10);
else
dimPosition.Set(1, outline[0][1] - 10);
createInstructions.TextLocation = dimPosition;

dimension = ((IpfcModel2D)drawing).CreateDrawingDimension(createInstructions);
((IpfcBaseDimension)dimension).Show(showInstructions);

if (c == 0)
{
hBaseLine = dimension.ConvertToBaseline(Csys3DPosition);
}
else
dimension.ConvertToOrdinate(hBaseLine);
}
Mylog.AddLog("Dimension for part " + task.sJobCode + " has been done.");
}

catch (Exception e)
{
Mylog.AddLog(" Faile to Generate dimension for Part " + task.sJobCode + "\n"+e.Message);
}

drawingMdl.Save();
if (DWGWindow != null)
DWGWindow.Close();
return true;
}

Many thanks for your help.

I will check your solution and use it in my problem.

 

Best regards.

Top Tags