Drafting Iso view

The journal below was submitted by user kam; it creates an isometric drafting view based on a selected view and a selected location. It allows you to quickly create an iso view with only a couple of clicks. The code should be run from the drafting application; there needs to be a drawing sheet with at least one view. When run, the journal will prompt you to select an existing view to use as the starting point of the isometric view. It will then prompt you to select a location on the drawing; the quadrant (taking the selected view as the origin) that you select will determine the orientation of the created isometric view. The code is written in C#.

Thanks kam, for sharing your code!

//This is a journal to create an iso view in drafting application.
//Select a base or projected view, then click on the sheet.
//One of the 4 iso views is created according to the mouse click location.
//NX9. Written in c#.
//2017-8-28 Kam

using System;
using NXOpen;
using NXOpen.UF;
using NXOpen.Drawings;
using MiniSnap;

class IsometricView
{
static Session _theSession = Session.GetSession();
static UFSession _theUFSession = UFSession.GetUFSession();
static Part _workPart = _theSession.Parts.Work;

public static void Main(string[] args) // Program entry point
{
//Prompt user to select a drafting view.
DraftingView viewSource = MySelect.SelectDraftingView("Select a drafting view.");
if (viewSource == null) return;

//Prompt user to click on the sheet to place an iso view.
NXOpen.View viewPicked;
Point3d p3dPicked = default(Point3d);
Selection.DialogResponse resp = UI.GetUI().SelectionManager.SelectScreenPosition(
"Click on the sheet to place an iso view.", //message
out viewPicked, // View of selected screen location
out p3dPicked); // Point3D : Selected screen position

//If user didn't click on the screen, then do nothing.
if (resp != Selection.DialogResponse.Pick) return;

//Copy the drafting view to the new location.
DraftingView viewCopy = null;
Tag tagViewCopy;
UFSession.GetUFSession().Draw.CopyView(viewSource.Tag, out tagViewCopy);
viewCopy = (DraftingView)NXOpen.Utilities.NXObjectManager.Get(tagViewCopy);
viewCopy.SetDrawingReferencePoint(p3dPicked);

//Get the location of mouse click relative to the source view.
Position posViewSource = viewSource.GetDrawingReferencePoint();
Position posPicked = p3dPicked;
Vector source2pick = posPicked - posViewSource;
int quadrant;
if ((source2pick.X >= 0) && (source2pick.Y >= 0))
quadrant = 1;
else if ((source2pick.X < 0) && (source2pick.Y >= 0))
quadrant = 2;
else if ((source2pick.X < 0) && (source2pick.Y < 0))
quadrant = 3;
else
quadrant = 4;

//Create Z vector of the iso view.
//It is the vector pointing to the eye in abs space.
//The location of mouse click determines the eye direction.
Vector vecISOZ = default(Vector);
Orientation oriSource = viewSource.Matrix;
switch (quadrant)
{
case 1:
vecISOZ = oriSource.AxisX + oriSource.AxisY + oriSource.AxisZ;
break;
case 2:
vecISOZ = -oriSource.AxisX + oriSource.AxisY + oriSource.AxisZ;
break;
case 3:
vecISOZ = -oriSource.AxisX - oriSource.AxisY + oriSource.AxisZ;
break;
case 4:
vecISOZ = oriSource.AxisX - oriSource.AxisY + oriSource.AxisZ;
break;
}

//Create X vector of iso view in abs space.
Vector vecISOX = Vector.Cross(oriSource.AxisY, vecISOZ);

//Create Y vector of iso view in abs space.
Vector vecISOY = Vector.Cross(vecISOZ, vecISOX);

//Create orientation of iso view in abs space.
Orientation oriISO = new Orientation(vecISOX, vecISOY);

//Orient the new view.
viewCopy.Style.Orientation.OrientView(oriISO);
viewCopy.Update();
}

public static int GetUnloadOption(string dummy)
{
return (int)Session.LibraryUnloadOption.Immediately;
//return (int)Session.LibraryUnloadOption.AtTermination;
}
}

class MySelect
{
public static DraftingView SelectDraftingView(string prompt)
{
//Declare variables to get data.
TaggedObject selobj = null;
Point3d cursor = default(Point3d);

//Deinfe filters for selection.
Selection.MaskTriple[] masks = { new Selection.MaskTriple(UFConstants.UF_view_type, UFConstants.UF_member_subtype, 0) };

//Prompt user to select a Tagged Object.
Selection.Response resp = UI.GetUI().SelectionManager.SelectTaggedObject(
prompt, //message
"Select a drafting view", //title
Selection.SelectionScope.WorkPart, //scope
Selection.SelectionAction.EnableSpecific, //action
false, //includeFeatures
false, //keepHighlighted
masks, //maskArray
out selobj,
out cursor);

//Cast and return an object.
return (DraftingView)selobj;
}
}

Comments

I forgot to update it.
The new journal does not copy and paste any annotations of the original view.

//This is a journal to create an iso view in drafting application.
//Select a base or projected view, then click on the sheet.
//One of the 4 iso views is created according to the mouse click location.
//NX9. Written in c#.
//2020-12-30 Kam

using System;
using NXOpen;
using NXOpen.UF;
using NXOpen.Drawings;
using MiniSnap;

class IsometricView
{
static Session _theSession = Session.GetSession();
static UFSession _theUFSession = UFSession.GetUFSession();
static Part _workPart = _theSession.Parts.Work;

public static void Main(string[] args) // Program entry point
{
//Prompt user to select a drafting view.
DraftingView viewSource = MySelect.SelectDraftingView("Select a drafting view.");
if (viewSource == null) return;

//Prompt user to click on the sheet to place an iso view.
NXOpen.View viewPicked;
Point3d p3dPicked = default(Point3d);
Selection.DialogResponse resp = UI.GetUI().SelectionManager.SelectScreenPosition(
"Click on the sheet to place an iso view.", //message
out viewPicked, // View of selected screen location
out p3dPicked); // Point3D : Selected screen position

//If user didn't click on the screen, then do nothing.
if (resp != Selection.DialogResponse.Pick) return;

//Copy the drafting view to the new location.
DraftingView[] viewsCopy;
_workPart.DraftingViews.PasteViews(
_workPart.DrawingSheets.CurrentDrawingSheet, //DrawingSheet
new DraftingView[] { viewSource }, //DraftingViews
DraftingViewCollection.ViewCopyDetailOption.DuplicateView, //DraftingViewCollection.ViewCopyDetailOption
DraftingViewCollection.ViewCopyAnnotOption.DontCopyAnnotation, //DraftingViewCollection.ViewCopyAnnotOption
out viewsCopy); //DraftingViews
DraftingView viewCopy = viewsCopy[0];
viewCopy.SetDrawingReferencePoint(p3dPicked);

//Get the location of mouse click relative to the source view.
Position posViewSource = viewSource.GetDrawingReferencePoint();
Position posPicked = p3dPicked;
Vector source2pick = posPicked - posViewSource;
int quadrant;
if ((source2pick.X >= 0) && (source2pick.Y >= 0))
quadrant = 1;
else if ((source2pick.X < 0) && (source2pick.Y >= 0))
quadrant = 2;
else if ((source2pick.X < 0) && (source2pick.Y < 0))
quadrant = 3;
else
quadrant = 4;

//Create Z vector of the iso view.
//It is the vector pointing to the eye in abs space.
//The location of mouse click determines the eye direction.
Vector vecISOZ = default(Vector);
Orientation oriSource = viewSource.Matrix;
switch (quadrant)
{
case 1:
vecISOZ = oriSource.AxisX + oriSource.AxisY + oriSource.AxisZ;
break;
case 2:
vecISOZ = -oriSource.AxisX + oriSource.AxisY + oriSource.AxisZ;
break;
case 3:
vecISOZ = -oriSource.AxisX - oriSource.AxisY + oriSource.AxisZ;
break;
case 4:
vecISOZ = oriSource.AxisX - oriSource.AxisY + oriSource.AxisZ;
break;
}

//Create X vector of iso view in abs space.
Vector vecISOX = Vector.Cross(oriSource.AxisY, vecISOZ);

//Create Y vector of iso view in abs space.
Vector vecISOY = Vector.Cross(vecISOZ, vecISOX);

//Create orientation of iso view in abs space.
Orientation oriISO = new Orientation(vecISOX, vecISOY);

//Orient the new view.
viewCopy.Style.Orientation.OrientView(oriISO);
viewCopy.Update();
}
}

class MySelect
{
public static DraftingView SelectDraftingView(string prompt)
{
//Declare variables to get data.
TaggedObject selobj = null;
Point3d cursor = default(Point3d);

//Deinfe filters for selection.
Selection.MaskTriple[] masks = { new Selection.MaskTriple(UFConstants.UF_view_type, UFConstants.UF_member_subtype, 0) };

//Prompt user to select a Tagged Object.
Selection.Response resp = UI.GetUI().SelectionManager.SelectTaggedObject(
prompt, //message
"Select a drafting view", //title
Selection.SelectionScope.WorkPart, //scope
Selection.SelectionAction.EnableSpecific, //action
false, //includeFeatures
false, //keepHighlighted
masks, //maskArray
out selobj,
out cursor);

//Cast and return an object.
return (DraftingView)selobj;
}
}