Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VB.net vs iLogic for Automated Centerlines giving different results - VB.net Automated Centerlines have 'crosshairs' instead line pointing towards center of circular pattern

2 REPLIES 2
Reply
Message 1 of 3
dtimm8RCUM
482 Views, 2 Replies

VB.net vs iLogic for Automated Centerlines giving different results - VB.net Automated Centerlines have 'crosshairs' instead line pointing towards center of circular pattern

I'm running into a strange issue where setting the Automated Centerlines in a VB.NET Inventor addin doesn't give the expected results. I tried digging around on these forums, but failed to find anybody else that mentioned this issue.

 

This is a snippet of the iLogic, and it does exactly what I want it to do.

Dim oBaseView As DrawingView
oBaseView = ThisApplication.ActiveDocument.Sheets(1).DrawingViews(1)

Dim oACS As AutomatedCenterlineSettings
oBaseView.GetAutomatedCenterlineSettings(oACS)
oACS.ApplytoHoles = True 
oACS.ApplyToCircularPatterns = True
oBaseView.SetAutomatedCenterlineSettings(oACS)

 

The result of the iLogic:

flange_good.png

 

 

Here is the code in VB.net.

 

'Does the automated centerlines command 
g_inventorApplication.StatusBarText = "Adding additional centerlines..."
Dim centerlineSettings As AutomatedCenterlineSettings = FlangePlateDrawing.DrawingSettings.AutomatedCenterlineSettings

FlangePlateDrawingSheet.DrawingViews.Item(1).GetAutomatedCenterlineSettings(centerlineSettings) 'Get
centerlineSettings.ApplyToBends = False
centerlineSettings.ApplyToCylinders = False
centerlineSettings.ApplyToFillets = False
centerlineSettings.ApplyToPunches = False
centerlineSettings.ApplyToRectangularPatterns = False
centerlineSettings.ApplyToRevolutions = False
centerlineSettings.ApplyToSketches = False
centerlineSettings.ApplyToWorkFeatures = False
centerlineSettings.ApplyToCircularPatterns = True
centerlineSettings.ApplyToHoles = True

centerlineSettings.ProjectionNormalAxis = True
centerlineSettings.ProjectionParallelAxis = False

centerlineSettings.RadiusThresholdPrecision = 2
  FlangePlateDrawingSheet.DrawingViews.Item(1).SetAutomatedCenterlineSettings(centerlineSettings) 'Set

 

 and here is the result of that code:

flange_bad.png

I've tried several times, such as commenting out all of the centerlineSettings lines that are being set to false, adding a delay before the FlangePlateDrawingSheet.DrawingViews.Item(1).SetAutomatedCenterlineSettings(centerlineSettings) line, and not including the ProjectionNormalAxis or RadiusThresholdPrecision values to make the code only have the same properties being set as the iLogic. One interesting thing I discovered in my debugging attempts is that if it doesn't set ApplyToCircularPatterns equal to True, I get the crosshairs centerlines for all of the holes. This lead me to think maybe it's processing too fast and putting the crosshairs centerlines in before it realizes that all of the holes are in the circular pattern. I thought adding a delay might fix that, but it did not.
I'm using Visual Studio 2019 to develop an addin for Inventor 2019 (originally for Inventor 2016).

 

Does anybody know why this is happening and how to fix it?

Labels (5)
2 REPLIES 2
Message 2 of 3
dtimm8RCUM
in reply to: dtimm8RCUM

I never found a way to get the automated centerlines to work, but I did find a workaround: manually add the centerlines. (Heavy inspired by: https://forums.autodesk.com/t5/inventor-customization/automated-centerline-orientation-for-holes-in-...)

 

In that link, @j.pavlicek mentioned the AddCenteredPattern subroutine. (I'll list below.) It does take some more code to pull it off, as you have to have a object collection for the bolt holes, but if you already have loops, select statements, and/or if statements to get object collections for arranging dimensions, it's not that much extra work.

 

Centerlines.AddCenteredPattern( PatternCenter As GeometryIntent, CenterEntities As ObjectCollection, [CentermarkStyle] As Variant, [Layer] As Variant, [Closed] As Boolean ) As Centerline

 

NameTypeDescription
PatternCenterGeometryIntentInput GeometryIntent that defines the a circular or elliptical drawing curve that defines the center of the pattern.
CenterEntitiesObjectCollectionInput ObjectCollection object that contains the set of entities that define the points the centerline passes through. Valid objects for input are GeometryIntent objects that reference circular or elliptical drawing curves, and center marks.
CentermarkStyleVariantObject that specifies the center mark style to use for the centerline. If not specified, the style defined by the active standard is used.
LayerVariantObject that specifies the layer to use for the centerline. If not specified, the layer defined by the active standard is used.
ClosedBoolean

Input Boolean that indicates if the centerline should be closed or not.

 

Here's the code I used, with the extra unrelated code for arranging dimensions stripped out.

Dim oBoltHoles As ObjectCollection
oBoltHoles = g_inventorApplication.TransientObjects.CreateObjectCollection

'Set reference to  drawingCurves
Dim oDrawingCurve_OuterDiameter As DrawingCurve = Nothing
For i = 1 To FlangePlateDrawingSheet.DrawingViews.Item(1).DrawingCurves.Count
	'Checks to see if the the curve has is a circle, and matches the drawing view center's location.
	If Not (FlangePlateDrawingSheet.DrawingViews.Item(1).DrawingCurves.Item(i).CenterPoint Is Nothing) Then
		If FlangePlateDrawingSheet.DrawingViews.Item(1).DrawingCurves.Item(i).CurveType = CurveTypeEnum.kCircleCurve AndAlso
		   FlangePlateDrawingSheet.DrawingViews.Item(1).DrawingCurves.Item(i).CenterPoint.X = FlangePlateDrawingSheet.DrawingViews.Item(1).Center.X And
		   FlangePlateDrawingSheet.DrawingViews.Item(1).DrawingCurves.Item(i).CenterPoint.Y = FlangePlateDrawingSheet.DrawingViews.Item(1).Center.Y Then
			'Checks to see if the drawingCurve is the flange's outer diameter drawingCurve.
			If oDrawingCurve_OuterDiameter Is Nothing Then
				oDrawingCurve_OuterDiameter = FlangePlateDrawingSheet.DrawingViews.Item(1).DrawingCurves.Item(i)
			ElseIf oDrawingCurve_OuterDiameter.ModelGeometry.Geometry.Radius < FlangePlateDrawingSheet.DrawingViews.Item(1).DrawingCurves.Item(i).ModelGeometry.Geometry.Radius Then
				'If the radius is greater, than this drawingCurve replaces the previously found drawingCurve
				oDrawingCurve_OuterDiameter = FlangePlateDrawingSheet.DrawingViews.Item(1).DrawingCurves.Item(i)
			End If
		ElseIf FlangePlateDrawingSheet.DrawingViews.Item(1).DrawingCurves.Item(i).CurveType = CurveTypeEnum.kCircleCurve Then
			oBoltHoles.Add(FlangePlateDrawingSheet.CreateGeometryIntent(FlangePlateDrawingSheet.DrawingViews.Item(1).DrawingCurves.Item(i)))
		End If
	End If
Next i

'Creates the Geomentry Intent for the OD, which will be used as the object to get the center for the centerline centered pattern.
Dim oGeometryIntent_OuterDiameter As GeometryIntent = FlangePlateDrawingSheet.CreateGeometryIntent(oDrawingCurve_OuterDiameter)

'Add Centerlines
g_inventorApplication.StatusBarText = "Adding additional centerlines..."
Try
	FlangePlateDrawingSheet.Centerlines.AddCenteredPattern(oGeometryIntent_OuterDiameter, oBoltHoles,,, True)
Catch ex As Exception
	MsgBox("Failed to add centerlines to the drawing." & vbCrLf & "Please manually add the centerlines once the automation finishes. (Right click -> Automated Centerlines)", vbCritical, "Error")
End Try

One note:
Without the "true" parameter at the end of the AddCenteredPatterns, the centerline would go though all of the holes, but there would be a gap between two of them. Changing the value from the default (of false), to true, it closes the centerline and has a complete circle.

Message 3 of 3
j.pavlicek
in reply to: dtimm8RCUM

@dtimm8RCUMNice.

I took the liberty of edit your code for better readability and formatting.

 

Dim oBoltHoles As ObjectCollection
oBoltHoles = g_inventorApplication.TransientObjects.CreateObjectCollection
Dim DrwView As DrawingView = FlangePlateDrawingSheet.DrawingViews.Item(1)

'Set reference to  drawingCurves
Dim oDrawingCurve_OuterDiameter As DrawingCurve = Nothing
For i = 1 To DrwView.DrawingCurves.Count
	Dim DrwCurve As DrawingCurve = DrwView.DrawingCurves.Item(i)
	'Checks to see if the the curve has is a circle, and matches the drawing view center's location.
	If Not (DrwCurve.CenterPoint Is Nothing) Then
		If DrwCurve.CurveType = CurveTypeEnum.kCircleCurve AndAlso
		   DrwCurve.CenterPoint.X = DrwView.Center.X And
		   DrwCurve.CenterPoint.Y = DrwView.Center.Y Then
			'Checks to see if the drawingCurve is the flange's outer diameter drawingCurve.
			If oDrawingCurve_OuterDiameter Is Nothing Then
				oDrawingCurve_OuterDiameter = DrwCurve
			ElseIf oDrawingCurve_OuterDiameter.ModelGeometry.Geometry.Radius < DrwCurve.ModelGeometry.Geometry.Radius Then
				'If the radius is greater, than this drawingCurve replaces the previously found drawingCurve
				oDrawingCurve_OuterDiameter = DrwCurve
			End If
		ElseIf DrwCurve.CurveType = CurveTypeEnum.kCircleCurve Then
			oBoltHoles.Add(FlangePlateDrawingSheet.CreateGeometryIntent(DrwCurve))
		End If
	End If
Next i

'Creates the Geomentry Intent for the OD, which will be used as the object to get the center for the centerline centered pattern.
Dim oGeometryIntent_OuterDiameter As GeometryIntent = FlangePlateDrawingSheet.CreateGeometryIntent(oDrawingCurve_OuterDiameter)

'Add Centerlines
g_inventorApplication.StatusBarText = "Adding additional centerlines..."
Try
	FlangePlateDrawingSheet.Centerlines.AddCenteredPattern(oGeometryIntent_OuterDiameter, oBoltHoles,,, True)
Catch ex As Exception
	MsgBox("Failed to add centerlines to the drawing." & vbCrLf & "Please manually add the centerlines once the automation finishes. (Right click -> Automated Centerlines)", vbCritical, "Error")
End Try

 



Inventor 2022, Windows 10 Pro
Sorry for bad English.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report