Hi,
I am changing the display dimension. I want to make the selection of changed dimension in a drawing file using Solid Works API C#
Is there a way to select particular Dimension in a drawing file using Solid Works API C#
Thanks,
Girish
SolidworksApi macros
Hi Girish Kumar,
Please try with below method it help you to select the dimension in drawing with respect to model display dimension.
2018 SOLIDWORKS API Help - GetCorresponding Method (IView)
Thanks
Manikandan
In Solid Works 2016, where can i make selection of dimension in drawing file.In this scenario i don't want to deal with part file.
can you provide some help with few lines of code?
Hi Girish,
Can you please provide the sample workflow.
Thanks
Manikandan
Hi Mani,
I want to make this dimension select through Solid works API C#.I want the selection of a particular dimension in a drawing file through code but couldn't overcome the problem.If its feasible to highlight the selection of dimension please let me know
Thanks,
Girish
Hi Girish,
Please go through the code,I hope it give the idea to solve.
static void Main(string[] args)
{
SldWorks SwApp = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("sldworks.Application");
ModelDoc2 SwModel = (ModelDoc2)SwApp.ActiveDoc;
DrawingDoc SwDraw =(DrawingDoc) SwModel;
//Activating the drawing view and add the dimension.
SwDraw.ActivateView("Drawing View1");
bool boolstatus = SwModel.Extension.SelectByRay(0.548750670735953, 0.454527552410178, -2000.2475, 0, 0, -1, 1.33869713731939E-03, 1, false, 0, 0);
boolstatus = SwModel.Extension.SelectByRay(0.537726106075676, 0.555323572161285, -2000.2475, 0, 0, -1, 1.33869713731939E-03, 1, true, 0, 0);
DisplayDimension Mydim = SwModel.AddDimension2(0.619771002485532, 0.508862906821227, 0);
SwModel.ClearSelection2(true);
//Get the annotation and selct the dimension.
Annotation Swann = Mydim.GetAnnotation();
Swann.Select(true);
}
Thanks
Manikandan
What are your requirements for the unique dimensions that you want to select. Are you looking to select them if they are a specific length? Are you looking to select them by name? This would help us determine a better approach for finding your dimensions.
Hi mani,
I need to select all the dimensions in drawing sheet, not just one.
Hi Alex,
I am looking for selection of all the dimensions in drawing file by name using solidworks api c#
I played around a bit with this so hopefully this works for you as well. It selected all DisplayDimension objects in all views on the current sheet.
<p> private void SelectAllDimensions(ModelDoc2 modelIn)</p><p> {</p><p> ModelDoc2 swDraw = default(ModelDoc2);</p><p> IDrawingDoc drawing = default(IDrawingDoc);</p><p> IAnnotation swAnno = default(IAnnotation);</p><p> View v = default(View);</p><p> Sheet swSheet = default(Sheet);</p><p> long annoType;</p><p> double start = DateTime.Now.TimeOfDay.TotalMilliseconds;</p><p> try</p><p> {</p><p> // Get base model file for the drawing</p><p> swDraw = modelIn;</p><p> // Cast as drawing since we know it's a drawing already</p><p> drawing = (IDrawingDoc)swDraw;</p><p></p><p></p><p> // If editing template, exit to edit sheet mode</p><p> if (!drawing.GetEditSheet())</p><p> drawing.EditSheet();</p><p></p><p></p><p> // Set sheet object as the current sheet</p><p> swSheet = (Sheet)drawing.GetCurrentSheet();</p><p></p><p></p><p> // Set the view object to the first view on the sheet</p><p> v = (View)drawing.GetFirstView();</p><p></p><p></p><p> // Loop through all drawing views</p><p> while (v != null)</p><p> {</p><p> // Get annotation for current view</p><p> swAnno = v.GetFirstAnnotation3();</p><p></p><p></p><p> // Loop through all annotations in this view</p><p> while (swAnno != null)</p><p> {</p><p> // Get annotation type and set layer based on type</p><p> annoType = swAnno.GetType();</p><p></p><p></p><p> // For all objects of DisplayDimension type, do the following</p><p> if (annoType == (long)swAnnotationType_e.swDisplayDimension)</p><p> {</p><p> // Select the DisplayDimension object and append to selection (true = allowing multiple selections)</p><p> swAnno.Select(true);</p><p> }</p><p></p><p></p><p> // Set annotation to next before the while loop restarts</p><p> swAnno = swAnno.GetNext3();</p><p> }</p><p> // set the view to the next view. this will return null if there are no more</p><p> v = (View)v.GetNextView();</p><p> }</p><p> }</p><p> catch (Exception e)</p><p> {</p><p> Trace.WriteLine(e.Message + " " + e.Data);</p><p> MessageBox.Show("Select All Dimensions Error", e.Message + System.Environment.NewLine + e.Data, MessageBoxButton.OK, MessageBoxImage.Error);</p><p> }</p><p> finally</p><p> {</p><p> // Let go of all references to solidworks objects</p><p> swDraw = null;</p><p> swAnno = null;</p><p> drawing = null;</p><p> v = null;</p><p> swSheet = null;</p><p> GC.Collect();</p><p></p><p></p><p> // Print duration for debugger</p><p> double finish = DateTime.Now.TimeOfDay.TotalMilliseconds;</p><p> Trace.WriteLine(string.Format("Select All Dimensions Duration: {0:#.00} seconds", (finish - start) / 1000));</p><p> }</p><p> }</p>Additionally, if you're selecting the dimensions by name, you can add an if statement around the Select() statement looking for the desired name.
Example:
<p>if (swAnno.GetName() == "RD11")</p><p>{</p><p> swAnno.Select(true);</p><p>}</p>