Forums:
Hello,
Need some help. I am a beginner and I am writing a journal to edit multiple PMI on drawing.
The code is written to modify Gap size of all existing Horizontal PMI. The code works when all the dimensions on the drawing are PMIHorizontal type. If I add another type of dimension like radial or non-PMIHorizontal or vertical dimensions I get error, but the journal would still modify all the existing Horizontal PMI with the new GAP value.
Please tell me what I am doing wrong.
Thanks
Bhavan
C#Code
usingSystem;//using System.Collections.Generic;//using System.ComponentModel;//using System.Data;//using System.Drawing;//using System.Linq;//using System.Text;//using System.Threading.Tasks;usingSystem.Windows.Forms;usingNXOpen;usingNXOpenUI;usingNXOpen.Annotations;usingNXOpen.UF; namespace WindowsFormsApplication1 {publicpartialclass EDIT_DIM : Form {public EDIT_DIM(){ InitializeComponent();} publicstaticint GetUnloadOption(string Dummy){return(int)NXOpen.Session.LibraryUnloadOption.Immediately;} privatevoid button1_Click(object sender, EventArgs e){ } privatevoid btn_GAP_Click(object sender, EventArgs e){ NXOpen.Session theSession = NXOpen.Session.GetSession(); NXOpen.Part workPart = theSession.Parts.Work; NXOpen.Part displayPart = theSession.Parts.Display; UFSession.GetUFSession().Abort.DisableAbort(); double GAP = Convert.ToDouble(tbGAP.Text), ViewScale; NXOpen.NXObject nXObject1; NXOpen.Annotations.PmiHorizontalDimension pmiHorizontalDimension1; NXOpen.DisplayableObject[] objects1; NXOpen.Annotations.EditSettingsBuilder editSettingsBuilder1;//var /*DIMType,*/ HorDIMType = "NXOpen.Annotations.PmiHorizontalDimension"; foreach(PmiHorizontalDimension PMIHor in workPart.Dimensions){//var DIMType = PMIHor.GetType().ToString(); //if (DIMType != HorDIMType)//{// break;//}//else if (DIMType == HorDIMType) { objects1 =new NXOpen.DisplayableObject[1]; pmiHorizontalDimension1 = PMIHor; objects1[0]= pmiHorizontalDimension1; ViewScale = PMIHor.GetAssociativity(1).ObjectView.Scale; editSettingsBuilder1 = workPart.SettingsManager.CreateAnnotationEditSettingsBuilder(objects1); editSettingsBuilder1.AnnotationStyle.LineArrowStyle.FirstPosToExtensionLineDistance= GAP * ViewScale; editSettingsBuilder1.AnnotationStyle.LineArrowStyle.SecondPosToExtensionLineDistance= GAP * ViewScale; nXObject1 = editSettingsBuilder1.Commit(); editSettingsBuilder1.Destroy();}} } }}
Full Error
System.InvalidCastException: Unable to cast object of type 'NXOpen.Annotations.RadiusDimension' to type 'NXOpen.Annotations.PmiHorizontalDimension'. at WindowsFormsApplication1.EDIT_DIM.btn_GAP_Click(Object sender, EventArgs e) in C:\Users\bhava\Documents\Visual Studio 2015\Projects\PMI_EDITOR\PMI_EDITOR\Form1.cs:line 49 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)