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

Exporting to STL with JLink

nborrerojr.
12-Amethyst

Exporting to STL with JLink

I am using JLink to export all parts in an assembly to STL files. During this, I also create an XML file with the position and rotation of each part in the assembly. (Not all parts export currently but I'm ignoring that for now). I am then importing the parts into another application. This is pretty close to working, but I am running into an issue where things seem kind of "inside out". I obviously can't post images to show what this looks like, but here is the code I'm using to store the position. Can anyone see anything I might be missing that is causing this? When I do the export to STL, I do not specify a coordinate system such as by using:

pfcModel.STLBinaryExportInstructions_Create().SetCsysName()

 

Here is the code for storing the position information.

public class PositionInAssembly {

    private String partName;
    private String assemblyName;
    private String partType;
    private int id;
    private Point3D origin;
    private Vector3D xAxis;
    private Vector3D yAxis;
    private Vector3D zAxis;

    public PositionInAssembly(String assemblyName, ComponentFeat componentFeat) throws jxthrowable {
        this.assemblyName = assemblyName;
        this.partName = componentFeat.GetModelDescr().GetFileName();
        this.id  = componentFeat.GetId();
        this.origin = componentFeat.GetPosition().GetOrigin();
        this.xAxis = componentFeat.GetPosition().GetXAxis();
        this.yAxis = componentFeat.GetPosition().GetYAxis();
        this.zAxis = componentFeat.GetPosition().GetZAxis();

        if (componentFeat.GetModelDescr().GetType() == ModelType.MDL_PART)
            partType = "part";
        else if (componentFeat.GetModelDescr().GetType() == ModelType.MDL_ASSEMBLY)
            partType = "assembly";
        else
            partType = componentFeat.GetModelDescr().GetType().getCipTypeName();
    }

    public String GetXML() {

        String x = "";
        String y = "";
        String z = "";
        String o = "";
        String coordinatesFormat = "%.5f,%.5f,%.5f";
        String parentId = "";

        try {
            x = String.format(coordinatesFormat, xAxis.get(0), xAxis.get(1), xAxis.get(2));
            y = String.format(coordinatesFormat, yAxis.get(0), yAxis.get(1), yAxis.get(2));
            z = String.format(coordinatesFormat, zAxis.get(0), zAxis.get(1), zAxis.get(2));
            o = String.format(coordinatesFormat, origin.get(0), origin.get(1), origin.get(2));

        } catch (com.ptc.cipjava.jxthrowable jxthrowable) {
            jxthrowable.printStackTrace();
        }
        return String.format("<%s name=\"%s\" parent=\"%s\" id=\"%s\">" +
                        "<origin>%s</origin><x>%s</x><y>%s</y><z>%s</z></%s>",
                partType, partName.replaceAll("[^a-zA-Z0-9_\\-\\.\\s]", "_"),
                assemblyName.replaceAll("[^a-zA-Z0-9_\\-\\.\\s]", "_"),
                id, o, x, y, z, partType);
    }
}
ACCEPTED SOLUTION

Accepted Solutions

In case anyone else runs into this, my problem was that +X in Creo was -X in the application I was importing the STLs into. I had to make sure to set the X coordinate to negative as well as the entire X vector (for rotation). I was apparently not properly negating it in one place or another and that was my problem.

View solution in original post

1 REPLY 1

In case anyone else runs into this, my problem was that +X in Creo was -X in the application I was importing the STLs into. I had to make sure to set the X coordinate to negative as well as the entire X vector (for rotation). I was apparently not properly negating it in one place or another and that was my problem.

Announcements


Top Tags