Create diameter dimension to all circle edges in Drawing View Using NX Open APIs | CAD Automation | ufs.Drf.CreateDiameterDim

Design Engineers always spend more time on drawings for several reasons. A few of them are;

  1. Drawings are prime source of information
  2. Quality of drawing needs to be accurate
  3. Every design iteration has small or big impact on drawings
  4. Design Engineers always look for simplifying drawings, not to specifiy duplicate details in it.
  5. and lot more reasons. 

In this example, I am going to show you how you can create diameter 0dimensions and place them with respect to view.

 

Steps used in below code are;

  1. Firstly, a program shall connect with drawing sheet, so do that ‘drgshts’ variable is used and using a loop, sheet with name ‘Sheet 1’ is fetched.
  2. Once drawing sheet is accessible, the nest step is to access the drawing views, here drawing view is also accessed using the view name ‘Front@7’.
  3. Next is to find the circle type drafting curves from the given drawing view. To get the drafting curves, AskVisibleObjects API is used.
  4. To filter the found drafting curves to only circle type drafting curves, the UFUNC (User Function) API member UFConstants.UF_circle_type is used.
  5. Next is used an API from UF Drafting namespace to create the diameter dimension, i.e. CreateDiameterDim. All necessary parameters are created and assigned values.
  6. As CreateDiameterDim is used in a loop, it keeps on iterating to create diameter dimension for all circle type drafting curves within the drawing view.
  7. For placement of dimension, MapModelToDrawing is usedto find the drafting curve location with respect to view and use the x and y co-ordiantes to place dimension on drawing sheet.
Option Strict Off
Imports System
Imports System.Collections

Imports NXOpen
Imports NXOpen.Drawings
Imports NXOpen.UF

Module add_diameter_dimensions_and_place_properly

Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = s.ListingWindow

Sub Main(ByVal args As String())

Dim dp As Part = s.Parts.Display()
lw.Open()

Dim drgshts As DrawingSheet() = dp.DrawingSheets.ToArray()

If drgshts.Length() > 0 Then
lw.WriteLine("Sheets found: " & drgshts.Length().ToString())
End If

Dim drgsht As DrawingSheet = Nothing
For Each thisSheet As DrawingSheet In drgshts
If thisSheet.Name = "Sheet 1" Then
drgsht = thisSheet
End If

Next
Dim drgview As BaseView = Nothing

For Each drgview1 As NXObject In drgsht.GetDraftingViews
If drgview1.Name = "Front@7" Then
drgview = drgview1
End If

Next

Dim org As Point3d = drgview.Origin
Dim ptorg1(2), ptorg2(1) As Double
ptorg1(0) = drgview.Origin.X
ptorg1(1) = drgview.Origin.Y
ptorg1(2) = drgview.Origin.Z

ufs.View.MapModelToDrawing(drgview.Tag, ptorg1, ptorg2)

For Each dftedg As NXObject In drgview.AskVisibleObjects
lw.WriteLine(dftedg.GetType().ToString)
Dim theObject As TaggedObject = dftedg

Dim objtype, objsubtype As Integer
ufs.Obj.AskTypeAndSubtype(theObject.Tag, objtype, objsubtype)

If objtype = UFConstants.UF_circle_type Then

Dim dftcurv1 As DraftingCurve = dftedg

Try

Dim ptloc As Point3d = dftcurv1.NameLocation
Dim dimpos1(2), dimpos2(1) As Double
dimpos1(0) = dftcurv1.NameLocation.X
dimpos1(1) = dftcurv1.NameLocation.Y
dimpos1(2) = dftcurv1.NameLocation.Z
lw.WriteLine(dimpos1(0) + dimpos1(1) + dimpos1(1))

ufs.View.MapModelToDrawing(drgview.Tag, dimpos1, dimpos2)
lw.WriteLine(dimpos2(0) + dimpos2(1))

Dim ufdrfobj As UFDrf.Object = New UFDrf.Object()
'Dim ufdrfobj2 As UFDrf.Object = New UFDrf.Object()
Dim uftext As UFDrf.Text = New UFDrf.Text()
ufdrfobj.object_tag = theObject.Tag
ufdrfobj.object_view_tag = drgview.Tag
ufdrfobj.object_assoc_type = UFDrf.AssocType.Intersection

Dim dimpos(2) As Double

If ptorg2(1) > dimpos2(1) Then
If ptorg2(0) > dimpos2(0) Then
dimpos2(0) = dimpos2(0) - 2
End If
If ptorg2(0) < dimpos2(0) Then
dimpos2(0) = dimpos2(0) + 2
End If
End If

Dim dimsn As Tag
ufs.Drf.CreateDiameterDim(ufdrfobj, uftext, dimpos2, dimsn)
'ufs.View.MapModelToDrawing(drgview.Tag, ptorg1, ptorg2)
Catch ex As Exception

End Try
End If

Next

For Each thisSheet As DrawingSheet In drgshts
lw.WriteLine(thisSheet.Name())
Next

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function

End Module

More information about the API used: UF_DRF_create_diameter_dim

Overview
Creates and displays a diameter dimension.
 
UF_DRF_object_p_tobjectInputData of arc object (see uf_drf_types.h)
Valid object types: arc, circle solid curve, cylindrical face
UF_DRF_text_t*drf_textInputAssociated text (see uf_drf_types.h)
doubledimension_3d_origin[3]Input3d dimension origin in wcs coordinates
tag_t*dimension_tagOutputObject tag of created diameter dimension

Social Connect

Learn CAD Automation using NX Open & Automate Design Tasks in Less Than 90 Days Without Any Prior Knowledge.

Attend the NX Open Masterclass to Discover

What’s Popular

Browse Popular, evergreen tutorials and how-to guides.

This journal get’s the name material used in part. Imports SystemImports NXOpenModule NXJournalSub Main (ByVal args() As String)Dim theSession As NXOpen.Session = …

This journal get’s the name material used in part. Imports SystemImports NXOpenModule NXJournalSub Main (ByVal args() As String)Dim theSession As NXOpen.Session = …

Datum Planes are a planar reference feature to help define other features, such as swept bodies and features at angles to the …

The use of computer-aided design (CAD) software has become an essential tool in engineering and manufacturing. There is no industry today that …

An attribute is a persistant way to store non-geometric data (i.e. not a point or curve or solid or feature). Attributes can …

An attribute is a persistant way to store non-geometric data (i.e. not a point or curve or solid or feature). Attributes can …

Design Engineers always spend more time on drawings for several reasons. A few of them are; Drawings are prime source of information …

It is quite possible to create a blank part and drawing sheet with one click of a button. Yes, you are right, …

NX Open is a powerful tool for automating NX CAD tasks. Below is source code that creates a new blank prt file …

As engineers and designers, we often have to work with complex 3D models and drawings, and extracting important information from these can …

NX Open is a powerful tool for working with imported geometries in NX.One common task that engineers and designers may need to …

https://youtu.be/5NWHlSM0sQ0 Q:Can you teach me nx open using visual basic .net? ChatGPT: Yes, I can help you get started with using Visual …

Leave a Comment

Your email address will not be published. Required fields are marked *