m_inventorApp

m_inventorApp

Anonymous
Not applicable
813 Views
9 Replies
Message 1 of 10

m_inventorApp

Anonymous
Not applicable

Dear all,

 

I am a beginner with using the inventor API and cant find out why the term in the title gives me an error.

you can find the code that I am trying to run on the page by using the following link: https://adndevblog.typepad.com/manufacturing/2012/06/creating-a-drawing-from-scratch-with-the-invent...

 

The error I am getting says: "compile error: Variable not defined"
Can someone please explain to me what "m_inventorApp" is, what the error means and how I can resolve this?

With kind regards,

 

Lennart

0 Likes
Accepted solutions (2)
814 Views
9 Replies
Replies (9)
Message 2 of 10

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

The m_inventorApp is the Inventor application object. I don't know from where you want to run this sub. But I made an example iLogic code for you. There's a problem in the original code that I fixed. The argument variable in the sub is called "app", but then the sub uses a variable called m_inventorApp. Thats just a misstake i guess... So if you change the name of the argument variable to m_inventorApp and pass the application object to it it works 🙂

 

I've tested this iLogic rule and it runs without any error. Just remember to rename the ipt you can download from the link to Part1.ipt and place it at the hard coded path. Then run this iLogic rule 🙂

 

Sub Main
	CreateDrawing(ThisApplication)
End Sub


Public Sub CreateDrawing(ByRef m_inventorApp As Inventor.Application)



	' Create a new drawing document using the default template.

	Dim oDrawDoc As DrawingDocument

	oDrawDoc = m_inventorApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, m_inventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject))



	Dim oSheet As Sheet

	oSheet = oDrawDoc.ActiveSheet



	' Open the part to be inserted into the drawing.

	Dim oPartDoc As PartDocument

	oPartDoc = m_inventorApp.Documents.Open("c:\temp\Part1.ipt", False)

	Dim oTG As TransientGeometry

	oTG = m_inventorApp.TransientGeometry



	MsgBox("Create base and orthographic views.")



	' Place the base front view.

	Dim oFrontView As DrawingView

	oFrontView = oSheet.DrawingViews.AddBaseView( _
	oPartDoc, _
	oTG.CreatePoint2d(15, 12), _
	3, _
	ViewOrientationTypeEnum.kFrontViewOrientation, _
	DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)



	' Create the top, right and iso views.

	Dim oTopView As DrawingView
	oTopView = oSheet.DrawingViews.AddProjectedView( _
	oFrontView, _
	oTG.CreatePoint2d(15, 30), _
	DrawingViewStyleEnum.kFromBaseDrawingViewStyle)



	Dim oIsoView As DrawingView

	oIsoView = oSheet.DrawingViews.AddProjectedView( _
	oFrontView, _
	oTG.CreatePoint2d(40, 30), _
	DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)



	MsgBox("Create section view.")



	' Create a front section view by

	' defining a section line in the front view.

	Dim oSectionSketch As DrawingSketch

	oSectionSketch = oFrontView.Sketches.Add



	oSectionSketch.Edit()



	' Get the circular edge of the top of the part.

	Dim oObjs As ObjectCollection

	oObjs = oPartDoc.AttributeManager.FindObjects("Name", "Name", "Edge13")

	Dim oCircularEdge As Edge

	oCircularEdge = oObjs.Item(1)



	' Get the associated drawingcurve.

	Dim oDrawViewCurves As DrawingCurvesEnumerator

	oDrawViewCurves = oFrontView.DrawingCurves(oCircularEdge)

	Dim oCircularCurve As DrawingCurve

	oCircularCurve = oDrawViewCurves.Item(1)



	Dim oCircularEntity As SketchEntity

	oCircularEntity = oSectionSketch.AddByProjectingEntity(oCircularCurve)



	' Draw the section line.

	Dim oSectionLine As SketchLine

	oSectionLine = oSectionSketch.SketchLines.AddByTwoPoints( _
	oTG.CreatePoint2d(0, 0.9), _
	oTG.CreatePoint2d(0, -0.9))



	' Create a constraint to the projected circle center point and the line.

	Call oSectionSketch.GeometricConstraints.AddCoincident( _
	oSectionLine, _
	oCircularEntity.CenterSketchPoint)



	oSectionSketch.ExitEdit()



	' Create the section view.

	Dim oSectionView As SectionDrawingView
	oSectionView = oSheet.DrawingViews.AddSectionView( _
	oFrontView, _
	oSectionSketch, _
	oTG.CreatePoint2d(34, 10), _
	DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, _
	Nothing, _
	False)



	MsgBox("Create detail view.")



	' Create the detail view.

	Dim oDetailView As DetailDrawingView

	oDetailView = oSheet.DrawingViews.AddDetailView( _
	oSectionView, _
	oTG.CreatePoint2d(35, 15), _
	DrawingViewStyleEnum.kFromBaseDrawingViewStyle, _
	False, _
	oTG.CreatePoint2d(21, 16), _
	oTG.CreatePoint2d(24, 18), , 10, , "A")



	' Get the various edges of the model.

	Dim aoEdges(0 To 13) As Edge

	Dim i As Integer

	For i = 1 To 13

		oObjs = oPartDoc.AttributeManager.FindObjects( _
		"Name", "Name", "Edge" & i)

		aoEdges(i) = oObjs.Item(1)

	Next



	' Get the equivalent drawing curves.

	Dim aoDrawCurves(0 To 13) As DrawingCurve

	For i = 1 To 13

		oDrawViewCurves = oFrontView.DrawingCurves(aoEdges(i))

		aoDrawCurves(i) = oDrawViewCurves.Item(1)

	Next



	MsgBox("Create dimensions to the curves in the view.")



	' Create some dimensions

	Dim oGeneralDims As GeneralDimensions

	oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions



	Dim oDim As GeneralDimension



	oDim = oGeneralDims.AddLinear( _
	oTG.CreatePoint2d(15.5, 13), _
	oSheet.CreateGeometryIntent(aoDrawCurves(1)), _
	oSheet.CreateGeometryIntent(aoDrawCurves(3)), _
	DimensionTypeEnum.kVerticalDimensionType)



	oDim = oGeneralDims.AddLinear( _
	oTG.CreatePoint2d(16, 9), _
	oSheet.CreateGeometryIntent(aoDrawCurves(2)), _
	oSheet.CreateGeometryIntent(aoDrawCurves(4)), _
	DimensionTypeEnum.kHorizontalDimensionType)



	oDim = oGeneralDims.AddRadius( _
	oTG.CreatePoint2d(17, 19), _
	oSheet.CreateGeometryIntent(aoDrawCurves(13)))



	oDim = oGeneralDims.AddDiameter( _
	oTG.CreatePoint2d(8, 20), _
	oSheet.CreateGeometryIntent(aoDrawCurves(13)), _
	True, False)



	MsgBox("Create a text box with a leader.")



	' Place a text box with a leader.

	Dim oObjColl As ObjectCollection

	oObjColl = m_inventorApp.TransientObjects.CreateObjectCollection

	Call oObjColl.Add(oTG.CreatePoint2d(17.5, 11))

	Dim oEval As Curve2dEvaluator

	oEval = aoDrawCurves(4).Evaluator2D

	Dim adParams(0) As Double

	adParams(0) = 0.6

	Dim adPoints(0 To 1) As Double

	Call oEval.GetPointAtParam(adParams, adPoints)



	Call oObjColl.Add(oTG.CreatePoint2d(adPoints(0), adPoints(1)))

	Dim oLeaderNote As LeaderNote

	oLeaderNote = oSheet.DrawingNotes.LeaderNotes.Add( _
	oObjColl, "Text with a leader")

	oLeaderNote.DimensionStyle = oLeaderNote.DimensionStyle



End Sub
Message 3 of 10

robertast
Collaborator
Collaborator

@JhoelForshav  I don’t stop to marvel at your abilities. As always, everything works great and with all the explanations for where it all came from. I will not stop repeating that there is nothing impossible for you. You will quickly create fully automated drawing creation with dimensional layout 😊

Message 4 of 10

JhoelForshav
Mentor
Mentor

Thank you @robertast ,

In this case though, the code was already written. I just changed the name of a variable and added the sub Main to call CreateDrawing from 😄

0 Likes
Message 5 of 10

Anonymous
Not applicable

Thank you @JhoelForshav for your quick response.

 I ran the code with the VBA editor.

If i run the code with your fix trough the VBA it gives an error but trough ilogic the first part works.

 

It calls the drawing but then gives an error.
its this error: (Exception from HRESULT: 0x80004005 (E_FAIL))


and this is the information it comes with:

System.Runtime.InteropServices.COMException (0x80004005): Niet nader omschreven fout (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.Documents.Open(String FullDocumentName, Boolean OpenVisible)
at ThisRule.CreateDrawing(Application& m_inventorApp)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)


 

0 Likes
Message 6 of 10

JhoelForshav
Mentor
Mentor
Accepted solution

@Anonymous 

This code is VB.NET not VBA, so it can't be ran through the VBA editor. iLogic is based on VB.NET however so there it works.

 

Well, yes. As I said you must download the part from the website you linked to. Rename the part file so its name is "Part1.ipt" and place it at the hard coded path.

See this line in the rule, thats what I'm talking about:

oPartDoc = m_inventorApp.Documents.Open("c:\temp\Part1.ipt", False)

If the part isn't named "Part1.ipt" and placed at "C:\temp" it will not work.

You can also change that full file name in the code to represent where your part is stored of course. But the part has to exist with the path and name that the rule tries to open it from 🙂

Message 7 of 10

Anonymous
Not applicable

thank you very much for your help and patience @JhoelForshav !
I've got it running! 

Message 8 of 10

Anonymous
Not applicable

Hello @JhoelForshav ,

I have another question about this topic. 
Since i got the code to work I tried to apply it to other parts and unfortunately ran into trouble again.

So creating a drawing and views works well. I get an error as the code tries to find the various edges.

As I look into the code I see the following: 

 

Dim aoEdges(0 To 13) As Edge

Dim i As Integer

For i = 1 To 13

oObjs = oPartDoc.AttributeManager.FindObjects( _
"Name", "Name", "Edge" & i)

aoEdges(i) = oObjs.Item(1)

Next

 

' Get the equivalent drawing curves.

Dim aoDrawCurves(0 To 13) As DrawingCurve

For i = 1 To 13

oDrawViewCurves = oFrontView.DrawingCurves(aoEdges(i))

aoDrawCurves(i) = oDrawViewCurves.Item(1)

Next

I do not really understand what is going on here. It seems that the edges have a value but i can not find those values. 

I could also be totally wrong😅
Could you please explain to me how the code finds the edges and where their value or name comes from?

 

Thank you in advance!

Lennart

 

0 Likes
Message 9 of 10

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

Yes, the part is prepared with attributes for these edges. Attributes are pretty much the same as properties but hidden from the user. If you have the attribute helper installed from the SDK you can use that to create attributes, but in case you don't I wrote this iLogic function to add attributes to edges  for you.

Dim oEdge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Pick edge")
If oEdge IsNot Nothing = False Then Exit Sub
Dim oSetName As String = InputBox("Attribute-set name: ", "Attribute set", "Name")
Dim oAttributeName As String = InputBox("Attribute name: ", "Attribute name", "Name")
Dim oAttributeValue As String = InputBox("Attribute value: ", "Attribute value", "Edge1")

Dim oDoc As PartDocument = ThisDoc.Document
Dim oSet As AttributeSet
If oEdge.AttributeSets.NameIsUsed(oSetName)
	oSet = oDoc.AttributeSets.Item(oSetName)
Else
	oSet = oEdge.AttributeSets.Add(oSetName)
End If
Dim oAttribute As Inventor.Attribute

If oSet.NameIsUsed(oAttributeName)
	oAttribute = oSet.Item(oAttributeName)
	oAttribute.Value = oAttributeName
Else
	oAttribute = oSet.Add(oAttributeName, ValueTypeEnum.kStringType, oAttributeValue)
End If

Just run the code, pick the edge in the part, set the attribute set name ("Name" is used for this in the example ipt), set the attribute name ("Name" is used for this as well in the part.) and finally set the attribute value ex. "Edge1").

 

If you want to delete all these attributesets for all edges you can run a code like this:

Dim oDoc As PartDocument = ThisDoc.Document
For Each oSurfBod As SurfaceBody In oDoc.ComponentDefinition.SurfaceBodies
	For Each oEdge As Edge In oSurfBod.Edges
		For Each oAttributeSet As AttributeSet In oEdge.AttributeSets
			oAttributeSet.Delete
		Next
	Next
Next

 

 

 

0 Likes
Message 10 of 10

Anonymous
Not applicable

Thank you very much again @JhoelForshav! I've learned a Lot from you!

0 Likes