IDW iLogic Dimensioning

IDW iLogic Dimensioning

layochim
Enthusiast Enthusiast
345 Views
4 Replies
Message 1 of 5

IDW iLogic Dimensioning

layochim
Enthusiast
Enthusiast

I'm trying to accomplish auto creating dimensions on a basic assembly after a rule generates and places views on an IDW.  I've been browsing for hours for a solution to this and have no luck.  Is there anyone that could help me with this?  I was thinking creating workpoints in my IAM then using code to retrieve those?

 

0 Likes
Accepted solutions (1)
346 Views
4 Replies
Replies (4)
Message 2 of 5

BM_Ashraf
Advocate
Advocate

Hi @layochim ,

Auto Dimension is a deep Topic and it varies from user to user. also always getting all Dimensions is really challenging.

Here is a ready to use Add-in 
https://bluemech.de/product/inventor-drawing_assistant/

 

It offers free and premium functions.

Maybe this Topic could give you a good start
https://forums.autodesk.com/t5/inventor-programming-ilogic/to-automate-the-dimension-using-curves-in...

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.

Blue Mech

Add-ins for Inventor!

0 Likes
Message 3 of 5

layochim
Enthusiast
Enthusiast

Thank you for the directions, through my research I've learned many have said auto dimensioning is complicated.  I've created a code to populate one dimension using two work points on one view, i'm struggling on how to get this to occur with all the other views.  The code i'm using is below. 

 

Public Sub Main()
	Dim viewNo As Integer = 1
	Dim dimPt1 As String = "WP1"
	Dim dimPt2 As String = "WP2"
	Dim dimType As String = "Aligned"
	'Dim dimText As String = "I made a dimension"
	Dim DimYOffset As Integer = 1
	Call AddLinearDim(viewNo, dimPt1, dimPt2, dimText, dimType,,DimYOffset)
End Sub

Private Sub AddLinearDim(viewNo As Integer,  
			dimPt1 As String, 
			dimPt2 As String, 
			dimText As String, 
			Optional dimType As String = "Aligned", 
			Optional DimXOffset As Integer = 0, 
			Optional DimYOffset As Integer = 0)
	
	Dim sDimText As String = dimText & " <DimensionValue/>" & " TIP TO TIP"
	'Set reference to drawing document
	Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
	'Set reference to view and sheet
	Dim oView As DrawingView = oDoc.ActiveSheet.DrawingViews(viewNo)
	Dim oSheet As Sheet = oDoc.ActiveSheet

	'Get reference to document in view
	Dim viewDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim viewDocDef As ComponentDefinition = viewDoc.ComponentDefinition
	
	'Get workpoints from the assembly document
	Dim oWP1 As WorkPoint = viewDocDef.WorkPoints.Item(dimPt1)
	Dim oWP2 As WorkPoint = viewDocDef.WorkPoints.Item(dimPt2)	

	'Place Centermarks where the Work Points reside
	Dim oCM1 As Centermark = oSheet.Centermarks.AddByWorkFeature(oWP1, oView)
	Dim oCM2 As Centermark = oSheet.Centermarks.AddByWorkFeature(oWP2, oView)
	oCM1.Visible = False
	oCM2.Visible = False	

	'Create Geometry Intent of the Centermarks
	Dim oGeomIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oCM1)
	Dim oGeomIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oCM2)
	'Define Dimension Orientation variables
	Dim dimTypeEnum As DimensionTypeEnum = Nothing

	'Filter by dimension type
	Select Case dimType
	    Case "Vertical"
	        dimTypeEnum = 60163
	    Case "Horizontal"
	        dimTypeEnum = 60162
	    Case "Aligned"
	        dimTypeEnum = 60161
	    Case Else
	        dimTypeEnum = 60161
	End Select

	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	
	'Declare variables for dimension endpoints
	Dim oShtPt1 As Point2d = oView.ModelToSheetSpace(oWP1.Point)
	Dim oShtPt2 As Point2d = oView.ModelToSheetSpace(oWP2.Point)
	'*** Control where the Dimension Text is located
	Dim oDimX As Double = oShtPt1.X	+ DimXOffset
	Dim oDimY As Double = oShtPt1.Y + DimYOffset
	Dim oPtText As Point2d = oTG.CreatePoint2d(oDimX, oDimY)

	'*** Create the Dimension
	Dim oDimension As DrawingDimension
	oDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPtText, oGeomIntent1, oGeomIntent2, dimTypeEnum)
	oDimension.CenterText

	'Add text to dimension
	Dim MyDimText As DimensionText = oDimension.Text
	MyDimText.FormattedText = sDimText
End Sub
0 Likes
Message 4 of 5

BM_Ashraf
Advocate
Advocate
Accepted solution

Hi,

Great start, well done!
I modified your script to work for all drawing views. Please note for some views it won't work. as maybe the two WP lay over each other.
Here also are some useful links.
http://hjalte.nl/37-auto-overall-dimension
http://hjalte.nl/77-adddimensionsdrawing
http://hjalte.nl/51-automatically-generate-bend-dimensions

http://hjalte.nl/40-hole-position-dimensions

 

Sub Main()
	'Set reference to drawing document
	Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
	'Set reference to view and sheet
	Dim oSheet As Sheet = oDoc.ActiveSheet
	'Get reference to document in view
For Each oView As DrawingView In oSheet.DrawingViews
	Dim viewDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim viewDocDef As ComponentDefinition = viewDoc.ComponentDefinition
	'Dim viewNo As Integer = 3
	Dim dimPt1 As String = "WP1"
	Dim dimPt2 As String = "WP2"
	Dim dimType As String = "Aligned"
	'Dim dimText As String = "I made a dimension"
	Dim DimYOffset As Integer = 1
	Call AddLinearDim(oSheet,oView,viewDocDef, dimPt1, dimPt2, dimText, dimType, , DimYOffset)
Next 

End Sub

Private Sub AddLinearDim(oSheet As Sheet,oView As DrawingView,viewDocDef As ComponentDefinition,dimPt1 As String, dimPt2 As String, dimText As String, 
			Optional dimType As String = "Aligned", Optional DimXOffset As Integer = 0, Optional DimYOffset As Integer = 0)
	
	Dim sDimText As String = dimText & " <DimensionValue/>" & " TIP TO TIP"

	'Get workpoints from the assembly document
	Dim oWP1 As WorkPoint = Nothing : Dim oWP2 As WorkPoint = Nothing
	Try
	oWP1 = viewDocDef.WorkPoints.Item(dimPt1)
	oWP2 = viewDocDef.WorkPoints.Item(dimPt2)	
	Catch 
	End Try
	
	If oWP1 Is Nothing Or oWP2 Is Nothing Then MsgBox("WP1 Or WP2 is Nothing") :Exit Sub
	

	'Place Centermarks where the Work Points reside
	Dim oCM1 As Centermark = oSheet.Centermarks.AddByWorkFeature(oWP1, oView)
	Dim oCM2 As Centermark = oSheet.Centermarks.AddByWorkFeature(oWP2, oView)
	oCM1.Visible = False
	oCM2.Visible = False	

	'Create Geometry Intent of the Centermarks
	Dim oGeomIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oCM1)
	Dim oGeomIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oCM2)
	'Define Dimension Orientation variables
	Dim dimTypeEnum As DimensionTypeEnum = Nothing

	'Filter by dimension type
	Select Case dimType
	    Case "Vertical"
	        dimTypeEnum = 60163
	    Case "Horizontal"
	        dimTypeEnum = 60162
	    Case "Aligned"
	        dimTypeEnum = 60161
	    Case Else
	        dimTypeEnum = 60161
	End Select

	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	
	'Declare variables for dimension endpoints
	Dim oShtPt1 As Point2d = oView.ModelToSheetSpace(oWP1.Point)
	Dim oShtPt2 As Point2d = oView.ModelToSheetSpace(oWP2.Point)
	'*** Control where the Dimension Text is located
	Dim oDimX As Double = oShtPt1.X	+ DimXOffset
	Dim oDimY As Double = oShtPt1.Y + DimYOffset
	Dim oPtText As Point2d = oTG.CreatePoint2d(oDimX, oDimY)

	'*** Create the Dimension
	Try
	Dim oDimension As DrawingDimension
	oDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPtText, oGeomIntent1, oGeomIntent2, dimTypeEnum)
	oDimension.CenterText

	'Add text to dimension
	Dim MyDimText As DimensionText = oDimension.Text
	MyDimText.FormattedText = sDimText
	Catch 
	End Try
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.

Blue Mech

Add-ins for Inventor!

0 Likes
Message 5 of 5

layochim
Enthusiast
Enthusiast

Ah that's great! Thank you! It worked!

0 Likes