Automated Drawing Dimensions

Automated Drawing Dimensions

Anonymous
Not applicable
716 Views
2 Replies
Message 1 of 3

Automated Drawing Dimensions

Anonymous
Not applicable

Hello,

 

first time posting, so if i did anything wrong, feel free to correct me.

 

I am fairly new to Inventor 2020, but throught this forum I already managed to create a pretty beautiful Assembly and Drawing document. Now I want to add automated dimensions through attributes.

In the assemblies I want do draw and dimension there is always one attribute called "Rollt_Top" and one "Fuss_Bot". I am fairly certain, that my code is able to find them and to create a Proxy out of them. I also think that the geometry intent work as they should, but i am not 100% sure. However with addLinear(Point, Intent1, Intent2) I always get an error (HRESULT: 0x80004005 (E_FAIL)))

 

Here is my code:

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet

Dim oView As DrawingView
oView = oSheet.DrawingViews.Item(1)

'Reference the Assembly On that view
Dim oAssembly As AssemblyDocument
oAssembly = oView.ReferencedDocumentDescriptor.ReferencedDocument

Dim oGeneralDims As GeneralDimensions
oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions

Dim Edge1 As Edge
Dim Edge2 As Edge
Dim oOccEdge1Proxy As EdgeProxy
Dim oOccEdge2Proxy As EdgeProxy

'Find the Model referenced in the Assembly
For Each oRef In oAssembly.AllReferencedDocuments
	
	oModelDoc = oRef
	
	Try
		'Find Face 1 on the model
		Dim oObjs1 As ObjectCollection
		oObjs1 = oModelDoc.AttributeManager.FindObjects("*", "*", "Rolle_Top")
		Edge1 = oObjs1.Item(1)
	Catch
	End Try
	Try
		'Find Face 2 on the model
		Dim oObjs2 As ObjectCollection
		oObjs2 = oModelDoc.AttributeManager.FindObjects("*", "*", "Fuss_Bot")
		Edge2 = oObjs2.Item(1)
	Catch
	End Try
Next


Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAssembly.ComponentDefinition.Occurrences.AllLeafOccurrences

' Iterate through the occurrences and print the name.
Dim oOcc As ComponentOccurrence
For Each oOcc In oLeafOccs
	If oOccEdge1Proxy Is Nothing Then
    	Try
    		Call oOcc.CreateGeometryProxy(Edge1, oOccEdge1Proxy)
		Catch
		End Try
	End If
	If oOccEdge2Proxy Is Nothing Then
		Try
    		Call oOcc.CreateGeometryProxy(Edge2, oOccEdge2Proxy)
		Catch
		End Try
	End If
Next 

Try
	Dim aoDrawCurves1 As DrawingCurve
	oDrawViewCurves = oView.DrawingCurves(oOccEdge1Proxy)
	aoDrawingCurves1 = oDrawViewCurves.Item(1)

	Dim aoDrawCurves2 As DrawingCurve
	oDrawViewCurves = oView.DrawingCurves(oOccEdge2Proxy)
	aoDrawingCurves2 = oDrawViewCurves.Item(1)

	Dim GI1 As GeometryIntent
	GI1 = oSheet.CreateGeometryIntent(aoDrawingCurves1)

	Dim GI2 As GeometryIntent
	GI2 = oSheet.CreateGeometryIntent(aoDrawingCurves2)

	Dim TextPoint As Point2d
	Dim XPos As Double
	Dim YPos As Double

	XPos = oView.Left - 0.5
	YPos = oView.Top - (oView.Height / 2)
	TextPoint = ThisApplication.TransientGeometry.CreatePoint2d(XPos, YPos)

	Dim oDim1 As GeneralDimension
	oDim1 = oGeneralDims.AddLinear(TextPoint, GI1, GI2)
Catch
End Try

Does anyone know what I am doing wrong?

 

Thanks for your help!

0 Likes
717 Views
2 Replies
Replies (2)
Message 2 of 3

J-Camper
Advisor
Advisor

It's hard to diagnose without a sample assembly, but from what I can see: 

 

Your "Rolle_Top" Attribute for Edge1 does not match the "Rollt_Top" in your comment.

 

Also are there multiple parts in the assembly that have edges with the attributes you are looking for?  Your loop casts each edge it would find over top of all previous edges, and the last edge might not be visible in your view later down the line.  I would set up an If/Then check after your first loop where you find the Edges, and if your edges aren't anything then throw a message and exit the rule.

 

You might also need to create the object collection before trying to fill it:

Dim CabinetCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

 

You have a lot of Try/Catch statements, but no Catch conditions, and some have an extremely long Try section.  You should put a message box at every Catch during the debugging phase so you know when you don't find what you're looking for.  The Try/Catch statement is nice to find initial objects where they might not exist, but after you start processing the objects you shouldn't need everything inside of a Try/Catch it it's working properly.  Having a Try/Catch around dimension creation is good, but it should be a focused Try/Catch and you should tell the user it failed in the Catch.

 

Again a sample assembly would be helpful for testing, I'm swinging in the dark right now.  Adding debug messages throughout will help verify where the issue is occurring.

 

0 Likes
Message 3 of 3

Anonymous
Not applicable

Hi,

 

Thanks for your reply. I try to answer to best of my abilities:

- Unfortunately I am not able so share the documents (Size and they are only for internal use)

-"Rollt_Top" was a Typo. It should be "Rolle_Top"

-There is always only one edge with the right name. In my assembly i have a rule to switch parts out but the replaced parts also have one right edge name

-I tried the if statement after each loop but it didn't change much so I left it out

-I tried to implement the sample code but unfortunately it didn't change anything

-I put everything in a Try/Catch because i kept getting a lot of errors but i will try to implement your recomandation

-The full error is:

"System.Runtime.InteropServices.COMException (0x80004005): Unbekannter Fehler (Ausnahme von HRESULT: 0x80004005 (E_FAIL))
bei System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
bei Inventor.GeneralDimensions.AddLinear(Point2d TextOrigin, GeometryIntent IntentOne, Object IntentTwo, DimensionTypeEnum DimensionType, Boolean ArrowheadsInside, Object DimensionStyle, Object Layer)
bei ThisRule.Main()
bei Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
bei iLogic.RuleEvalContainer.ExecRuleEval(String execRule)"

 

I realised that the Rule works, if both Edges are found on the same part. But when it is not on the same part but within the assembly I get the error from above.

is it possible, that this is the problem?

 

Thanks for your help!

 

0 Likes