Cancel
Showing results for 
Search instead for 
Did you mean: 

Journal for turning modeling text to drafting notes

Creator
Creator

Is there a Journal or does anyone know on how to go about making a journal that would convert modeling text into a drafting note? Reason being, the ability to use the planar text operation intead of curve point or planar mill. A journal  in my opinion, would save some time and would satisfy the wants of the design and programming. 

 

Thanks  

3 REPLIES 3

Re: Journal for turning modeling text to drafting notes

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

If you planar mill, when selecting the curves to "engrave" (which is what the text option does), make sure to set the one filter to "feature curves".

That way as the text is edited (letteres added/deleted, font changed, etc.) all the lettering will still be engraved.

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP16/TC11.2
I'd rather be e-steamed than e-diseaseled


Re: Journal for turning modeling text to drafting notes

Creator
Creator

Thanks for the response. I realize you can do that, but if using feature curves the boundary connects between the characters (members of the boundary) and in nx12 with the new boundary creation it makes it a pain to make your curves "On" instead of "tanto" because you have to go and edit the boundary after it is created rather than up front.

Re: Journal for turning modeling text to drafting notes

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Hi @Mbruggeman,

Based on the Sample NX Open .NET C# program : FillPlanarCurvesFromFeatureText  from the GTAC:

using System;
using NXOpen;
using NXOpen.UF;
using NXOpen.Utilities;

public class Program
{
    // class members
    private static Session theSession = null;
    private static UI theUI = null;
    private static UFSession theUfSession = null;
    private static Part workPart = null;
    private static ListingWindow lw = null;
    public static Program theProgram;
    public static bool isDisposeCalled;
    private static bool isDebug = false;

    //------------------------------------------------------------------------------
    // Constructor
    //------------------------------------------------------------------------------
    public Program()
    {
        try
        {
            theSession = Session.GetSession();
            theUI = UI.GetUI();
            theUfSession = UFSession.GetUFSession();
            workPart = theSession.Parts.Work;
            lw = theSession.ListingWindow;
            isDisposeCalled = false;
        }
        catch (NXOpen.NXException ex)
        {
            // ---- Enter your exception handling code here -----
            // UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
        }
    }

    //------------------------------------------------------------------------------
    //  Explicit Activation
    //      This entry point is used to activate the application explicitly
    //------------------------------------------------------------------------------
    public static int Main(string[] args)
    {
        int retValue = 0;
        try
        {
            theProgram = new Program();

            //TODO: Add your application code here 
            lw.Open();
            text_convert();

            theProgram.Dispose();
        }
        catch (NXOpen.NXException ex)
        {
            // ---- Enter your exception handling code here -----

        }
        return retValue;
    }

    //------------------------------------------------------------------------------
    // Following method disposes all the class members
    //------------------------------------------------------------------------------
    public void Dispose()
    {
        try
        {
            if (isDisposeCalled == false)
            {
                //TODO: Add your application code here 
            }
            isDisposeCalled = true;
        }
        catch (NXOpen.NXException ex)
        {
            // ---- Enter your exception handling code here -----

        }
    }

    public static int GetUnloadOption(string arg)
    {
        //Unloads the image explicitly, via an unload dialog
        //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);

        //Unloads the image immediately after execution within NX
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);

        //Unloads the image when the NX session terminates
        // return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
    }

    public static int text_convert()
    {

        try
        {
            int count = 1;

            NXOpen.Features.FeatureCollection featureCollection = workPart.Features;

            foreach (NXOpen.Features.Feature feature in featureCollection)
            {
                if (feature.FeatureType.ToString().ToLower() == "text")
                {
                    if (!feature.Suppressed)
                    {
                        NXOpen.Features.Text text = (NXOpen.Features.Text)feature;
                        NXOpen.Features.TextBuilder textBuilder = workPart.Features.CreateTextBuilder(text);
                        lw.WriteFullline(textBuilder.TextString.ToString());
                        

                        Tag currentWcsTag = Tag.Null;
                        theUfSession.Csys.AskWcs(out currentWcsTag);

                        bool isDisplay = workPart.WCS.Visibility;
                        workPart.WCS.Visibility = false;

                        if (OrientCoordinatesSystem(textBuilder.Type, textBuilder))
                        {
                        //NXOpen.Session.UndoMarkId undoMarkId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start Area Fill");
                        theSession.ListingWindow.WriteLine(count.ToString() + ".Feature Name : " + feature.GetFeatureName().ToString() + "\n\tText String    : " + "\"" + textBuilder.TextString + "\"" + "\n\tPlacement Type : " + textBuilder.Type);
                        //FillCurvesFromFeatureText(text.GetEntities());
                        //theSession.SetUndoMarkName(undoMarkId, "Area Fill");
                        }

                        NXOpen.Tag theNote = Tag.Null;
                        int num_lines = 1;
                        String[] textString = new string[1];
                        textString[0] = textBuilder.TextString.ToString();

                        double[] origin_3d = { 0, 0, 0 };
                        int orientation = 0;

                        NXOpen.Session.UndoMarkId undoMarkId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Text Convert");


                        theUfSession.Drf.CreateNote(num_lines, textString, origin_3d, orientation, out theNote);

                        NXOpen.Annotations.Note note1 = (NXOpen.Annotations.Note)NXObjectManager.Get(theNote);
                        NXOpen.Annotations.DraftingNoteBuilder draftingNoteBuilder1 = null;
                        draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(note1);
                        draftingNoteBuilder1.Style.LetteringStyle.GeneralTextSize = Convert.ToDouble(textBuilder.PlanarFrame.Height.RightHandSide);
                        NXOpen.NXObject nXObject1 = null;
                        nXObject1 = draftingNoteBuilder1.Commit();
                        draftingNoteBuilder1.Destroy();

                        theUfSession.Csys.SetWcs(currentWcsTag);
                        if (isDisplay) workPart.WCS.Visibility = true;
                        textBuilder.Destroy();
                        count++;
                    } /* if Suppressed */
                } /* if FeatureType */
            } /* foreach */
        }
        catch (NXOpen.NXException ex)
        {
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
        }

        return 0;
    }


    //------------------------------------------------------------------------------
    //             Method : OrientCoordinatesSystem
    //
    //  Set the WCS Normal to the Planar Feature Text
    //
    //  Input NXOpen.Features.TextBuilder.Types : The Placement Type (Planar, Face or On Curve)
    //  Input NXOpen.Features.TextBuilder       : The Text Builder to Query
    //  Return Boolean                          : True for Valid Placement else False
    //-----------------------------------------------------------------------------
    public static bool OrientCoordinatesSystem(NXOpen.Features.TextBuilder.Types types, NXOpen.Features.TextBuilder textBuilder)
    {
        bool validPlacement = false;

        switch (types)
        {
            case NXOpen.Features.TextBuilder.Types.OnFace:
                if (isDebug) theSession.ListingWindow.WriteLine("Planar Text on Face.");
                ScCollector scCollector = textBuilder.PlacementFaces;
                validPlacement = SetWCSNormalToPlanarFace(scCollector.GetObjects());
                break;

            case NXOpen.Features.TextBuilder.Types.Planar:
                if (isDebug) theSession.ListingWindow.WriteLine("Planar Text on Plane.");
                SetWCSNormalToPlanarText(textBuilder.PlanarFrame.CoordinateSystem);
                validPlacement = true;
                break;

            case NXOpen.Features.TextBuilder.Types.OnCurve:
                if (isDebug) theSession.ListingWindow.WriteLine("Planar Text on Curve.");
                SectionData[] sectionDatas = null;
                NXObject[] nXObjects = null;
                textBuilder.OnCurvePlacementProfile.GetOutputCurves(out nXObjects);
                textBuilder.OnCurvePlacementProfile.GetSectionData(out sectionDatas);
                SetWCSNormalToCurve(nXObjects, sectionDatas);
                validPlacement = true;
                break;

            default:
                if (isDebug) theSession.ListingWindow.WriteLine("Unknown Placement Type.");
                validPlacement = false;
                break;
        }

        return validPlacement;
    }

    //------------------------------------------------------------------------------
    //             Method : SetWCSNormalToCurve
    //
    //  Search the First Coplanar Object (Arc or Spline) then Set the WCS Normal
    //  to the Text Placement Curves.
    //
    //  Input NXObject    : The Placement Curves
    //  Input SectionData : The Section Data (for Spline only)
    //  Return            : None
    //------------------------------------------------------------------------------
    public static void SetWCSNormalToCurve(NXObject[] nXObjects, SectionData[] sectionDatas)
    {
        int type = 0, subType = 0;

        bool validMatrix = false;

        try
        {
            for (int i = 0; i < nXObjects.Length; i++)
            {
                theUfSession.Obj.AskTypeAndSubtype(nXObjects[i].Tag, out type, out subType);

                switch (type)
                {
                    case UFConstants.UF_circle_type:

                        Point3d arcCenter = new Point3d(0.0, 0.0, 0.0);
                        Vector3d xDirection = new Vector3d(1.0, 0.0, 0.0);
                        Vector3d yDirection = new Vector3d(0.0, 1.0, 0.0); ;

                        Arc arc = (Arc)(NXObjectManager.Get(nXObjects[i].Tag));
                        arc.GetOrientation(out arcCenter, out xDirection, out yDirection);

                        if (isDebug)
                        {
                            theSession.ListingWindow.WriteLine("Arc Center  : X" + arc.CenterPoint.X + " Y" + arc.CenterPoint.Y + " Z" + arc.CenterPoint.Z);
                            theSession.ListingWindow.WriteLine("X Direction : X" + xDirection.X + " Y" + xDirection.Y + " Z" + xDirection.Z);
                            theSession.ListingWindow.WriteLine("Y Direction : X" + yDirection.X + " Y" + yDirection.Y + " Z" + yDirection.Z);
                        }

                        NXOpen.Direction direction1 = theSession.Parts.Work.Directions.CreateDirection(arcCenter, xDirection, NXOpen.SmartObject.UpdateOption.AfterModeling);
                        NXOpen.Direction direction2 = theSession.Parts.Work.Directions.CreateDirection(arcCenter, yDirection, NXOpen.SmartObject.UpdateOption.AfterModeling);

                        SetWCSToXForm(theSession.Parts.Work.Xforms.CreateXform(theSession.Parts.Work.Points.CreatePoint(arcCenter), direction1, direction2, NXOpen.SmartObject.UpdateOption.AfterModeling, 1.0));

                        validMatrix = true;
                        break;

                    case UFConstants.UF_spline_type:

                        for (int j = 0; j < sectionDatas.Length; j++)
                        {
                            SectionElementData[] sectionElementDatas;
                            sectionDatas[j].GetSectionElementsData(out sectionElementDatas);

                            for (int k = 0; k < sectionElementDatas.Length; k++)
                            {
                                DisplayableObject displayableObject = null;
                                DisplayableObject startConnector = null;
                                DisplayableObject endConnector = null;

                                Point3d startPoint = new Point3d(0.0, 0.0, 0.0);
                                Point3d endPoint = new Point3d(0.0, 0.0, 0.0);

                                sectionElementDatas[k].GetSectionElementData1(out displayableObject, out startConnector, out startPoint, out endConnector, out endPoint);
                                theUfSession.Obj.AskTypeAndSubtype(displayableObject.Tag, out type, out subType);

                                if (type == UFConstants.UF_spline_type)
                                {
                                    NXOpen.Spline spline = (Spline)(NXObjectManager.Get(displayableObject.Tag));
                                    SetWCSToXForm(theSession.Parts.Work.Xforms.CreateXform(spline, NXOpen.SmartObject.UpdateOption.AfterModeling));     /* Placement Spline is Always Coplanar for Feature Text */
                                    validMatrix = true;
                                    break;
                                } /* if type */
                            } /* for int k = 0 */

                            if (validMatrix) break;
                        } /* for int j = 0 */
                        break;

                    case UFConstants.UF_line_type:
                        validMatrix = false;
                        break;

                    default:
                        validMatrix = false;
                        break;
                } /* switch */

                if (validMatrix) break; /* Found a Valid Planar Curve/Spline , so no Need to Continue */
            } /* for int i = 0 */
        }
        catch (NXOpen.NXException ex)
        {
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
        }
    }

    //------------------------------------------------------------------------------
    //             Method : SetWCSToXForm
    //
    //  Set the WCS to an Xform
    //
    //  Input NXOpen.Xform : The Xform where to Place Csys
    //  Return             : None
    //------------------------------------------------------------------------------
    public static void SetWCSToXForm(NXOpen.Xform xform)
    {
        Tag matrixTag = Tag.Null;

        double[] matrixValues = new double[9];

        NXOpen.Matrix3x3 matrix = new NXOpen.Matrix3x3();

        try
        {
            NXOpen.CartesianCoordinateSystem cartesianCoordinateSystem = theSession.Parts.Work.CoordinateSystems.CreateCoordinateSystem(xform, NXOpen.SmartObject.UpdateOption.AfterModeling);

            theUfSession.Csys.AskMatrixOfObject(cartesianCoordinateSystem.Tag, out matrixTag);
            theUfSession.Csys.AskMatrixValues(matrixTag, matrixValues);

            matrix.Xx = matrixValues[0];
            matrix.Xy = matrixValues[1];
            matrix.Xz = matrixValues[2];
            matrix.Yx = matrixValues[3];
            matrix.Yy = matrixValues[4];
            matrix.Yz = matrixValues[5];
            matrix.Zx = matrixValues[6];
            matrix.Zy = matrixValues[7];
            matrix.Zz = matrixValues[8];

            theSession.Parts.Work.WCS.SetOriginAndMatrix(cartesianCoordinateSystem.Origin, matrix);
        }
        catch (NXOpen.NXException ex)
        {
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
        }
    }

    //------------------------------------------------------------------------------
    //             Method : SetWCSNormalToPlanarText
    //
    //  Set the WCS Normal to the Planar Feature Text (Placement Type : Planar)
    //
    //  Input CoordinateSystem : The Coordinate System where the Feature is Placed
    //  Return                 : None
    //------------------------------------------------------------------------------
    public static void SetWCSNormalToPlanarText(NXOpen.CoordinateSystem coordinateSystem)
    {
        Tag matrixTag = Tag.Null;

        double[] matrixValues = new double[9];

        try
        {
            theUfSession.Csys.AskMatrixOfObject(coordinateSystem.Tag, out matrixTag);
            theUfSession.Csys.AskMatrixValues(matrixTag, matrixValues);

            NXOpen.Matrix3x3 matrix = new NXOpen.Matrix3x3();
            matrix.Xx = matrixValues[0];
            matrix.Xy = matrixValues[1];
            matrix.Xz = matrixValues[2];
            matrix.Yx = matrixValues[3];
            matrix.Yy = matrixValues[4];
            matrix.Yz = matrixValues[5];
            matrix.Zx = matrixValues[6];
            matrix.Zy = matrixValues[7];
            matrix.Zz = matrixValues[8];

            theSession.Parts.Work.WCS.SetOriginAndMatrix(coordinateSystem.Origin, matrix);
        }
        catch (NXOpen.NXException ex)
        {
            UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
        }
    }

    //------------------------------------------------------------------------------
    //             Method : SetWCSNormalToPlanarFace
    //
    //  Set the WCS Normal to the First Face where the Feature Text is 
    //  Placed (Placement Type : Face)
    //
    //  Input TaggedObject : The Selected Faces where the Feature Text is Positionning
    //  Return Boolean     : Return Valid Orientation else false
    //------------------------------------------------------------------------------
    public static bool SetWCSNormalToPlanarFace(TaggedObject[] taggedObjects)
    {
        bool validPlacement = false;

        for (int i = 0; i < taggedObjects.Length; i++)
        {
            int type = 0, subType = 0;
            int faceType = 0;

            theUfSession.Obj.AskTypeAndSubtype(taggedObjects[i].Tag, out type, out subType);
            theUfSession.Modl.AskFaceType(taggedObjects[i].Tag, out faceType);

            if (isDebug) theSession.ListingWindow.WriteLine("Type : " + type + " SubType : " + subType + " Face Type : " + faceType);

            if (faceType == 22) /* For Planar Face Only */
            {
                double[] matrixValues = new double[9];
                Face face = (Face)(NXObjectManager.Get(taggedObjects[i].Tag));
                SetWCSToXForm(theSession.Parts.Work.Xforms.CreateXform(face, NXOpen.SmartObject.UpdateOption.AfterModeling));
                validPlacement = true;
                break;
            } /* if faceType */
        } /* for int i = 0 */

        return validPlacement;
    }
}

But I don't use th convert method. I wrote it with different method, see the attached picture.

Attila Szepesi, Application Engineer, graphIT Ltd.
Production: NX12.0.2 NX1863 | TcUA 11.3
Development: VB.NET, C# Testing: NX--

Learn online





Solution Information