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

How to create a circle in a Creo4 drawing using java toolkit?

Highlighted
Contributor

How to create a circle in a Creo4 drawing using java toolkit?

Documentation for the Creo java toolkit is abysmal so I turn to the community for help.  

I found example of how to create line here:
C:\Program Files\PTC\Creo 4.0\M030\Common Files\otk_java_free\otk_java_appls\jlinkexamples\pfcDrawingExamples.java

I modified it to create a circle instead like this:
public static void createCircle() throws com.ptc.cipjava.jxthrowable
{
StdColor color = StdColor.COLOR_QUILT;
Session session = pfcSession.GetCurrentSession ();

Model model = session.GetCurrentModel();

if (model.GetType() != ModelType.MDL_DRAWING)
throw new RuntimeException ("Current model is not a drawing");

Drawing drawing = (Drawing) model;

int currSheet = drawing.GetCurrentSheetNumber();
View2D view = drawing.GetSheetBackgroundView (currSheet);

Point3D circleCenter = Point3D.create();
circleCenter.set(0, 100); //x
circleCenter.set(1, 100); //y
circleCenter.set(2, 0); //z
Vector3D vd = Vector3D.create();
double diameter = 50;
printMsg("createCircle: about to pfcGeometry.CircleDescriptor_Create...");
CircleDescriptor circleDescriptor = pfcGeometry.CircleDescriptor_Create(circleCenter, diameter, vd);

printMsg("createCircle: about to pfcDetail.DetailEntityInstructions_Create...");
DetailEntityInstructions instrs = pfcDetail.DetailEntityInstructions_Create (circleDescriptor, view);
ColorRGB rgb = session.GetRGBFromStdColor (color);
instrs.SetColor(rgb); 
printMsg("createCircle: about to drawing.CreateDetailItem...");
drawing.CreateDetailItem (instrs);
session.GetCurrentWindow().Repaint(); 
}

Program starts up and prints some debugging statements but then fails here:
createCircle: about to drawing.CreateDetailItem...
Exception caught: com.ptc.wfc.Implementation.pfcExceptions$XToolkitGeneralError

I suspect its because of the empty Vector3D in here:
pfcGeometry.CircleDescriptor_Create(circleCenter, diameter, vd);

What is vd supposed to be? Also, am I setting the circleCenter points correctly? Documentation anywhere?

Tags (1)
2 REPLIES 2

Re: How to create a circle in a Creo4 drawing using java toolkit?

I've never done any toolkit programming, so I don't know anything about the specifics of your troubles.

However, I have done quite a bit of Java programming. For documentation, if the .jar files used for toolkit are up to proper standards, they should have Javadoc code embedded in them. You could try to generate the Javadoc for the specific toolkit you are dealing with and if it is properly documented you might get some hints.

Mathematically, what you are providing for the circle definition is insufficient. You say you're creating this on a "drawing", but it appears that the definition is actually not 2D but 3D. Therefore, just a point and a diameter is not enough to define it. You need:

(1) The center point, a 3D point.

(2) A diameter to specify the size of the circle.

(3) A vector, probably a unit vector, to define the normal to the plane of the circle.

Without a properly defined vector, there are an infinite number of circles possible with the point and diameter alone. Likely the Vector3D that you are using initializes to i = 0, j = 0, k = 0. So that might be causing an exception to be thrown, too.

Re: How to create a circle in a Creo4 drawing using java toolkit?

Hi Ken,

Ooh, that was a really good tip.  Unfortunately it didn't solve the problem.  I set the unit vector like this:

Vector3D vd = Vector3D.create(); //this is the normal vector. make it normal to the xy plane
vd.set(0, 0); //x
vd.set(1, 0); //y
vd.set(2, 1); //z

 

But still getting the same error.  Just grasping for straws without documentation.  Shameful.  I will try your javadoc idea.  Thank you!

Greg