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: 

My ilogic code can't run it got the following error, I hope the experts can help me

14 REPLIES 14
Reply
Message 1 of 15
ngtatsang98
771 Views, 14 Replies

My ilogic code can't run it got the following error, I hope the experts can help me

Code ilogic của mình không chạy được nó bị lỗi như sau, mong các chuyên gia giúp mình

 

Labels (1)
14 REPLIES 14
Message 2 of 15
ngtatsang98
in reply to: ngtatsang98

ilogic , automatically export drawings with errors

Message 3 of 15
A.Acheson
in reply to: ngtatsang98

Hi @ngtatsang98 

Can you show the more info tab of the error message box? The first tab only suggest there is an error but the second will give a little more information as to what the error is. Also have you narrowed down approximately where the rule is failing? If not place in a message box move it down each line untill you cannot see it being launched. This will help narrow down what to look at. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 4 of 15
ngtatsang98
in reply to: A.Acheson

More infor:
System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.Documents.Add(DocumentTypeEnum DocumentType, String TemplateFileName, Boolean CreateVisible)
at LmiRuleScript.CreateDrawing_PlaceViews(String PartNumber, Double DrawingViewScale, String ViewsToPlace, Boolean AssemblyDrawing, DrawingView& oBaseView, DrawingView& oView2, DrawingView& oView3, DrawingView& oView4)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

Message 5 of 15
A.Acheson
in reply to: ngtatsang98

Hi @ngtatsang98 

The error suggest there is a missing string object. Does the template file path exist? There could be other string errors but that is a good one to check first. If it does exist I would suggest turn off all other actions and get that function to work first. 

 

In Function CreateDrawing_PlaceViews Check this path.

"C:\Users\Public\Documents\Autodesk\Inventor 2017\Templates\standard.dwg"

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 6 of 15
ngtatsang98
in reply to: A.Acheson

yes it worked partially then got the error again

Error in rule: Rule0, in document: Part5.ipt

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

More info:

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.DimensionStylesEnumerator.get_Item(Object Index)
at LmiRuleScript.CreateLinearDimension(DrawingDocument oDrawingDoc, DrawingView oDrawingView, DoubleForEquals DimensionLength, String DirectionOfDim, Double OffsetDistance, String DimensionLocation, Boolean ReferencedDim)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

Message 7 of 15
A.Acheson
in reply to: ngtatsang98

You have a string error in 

String "DimensionLocation" but I am not sure why it is saying in part5.ipt. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 8 of 15
ngtatsang98
in reply to: A.Acheson

it still doesn't seem to work , part5 is the filename where i run this code .
This code is not written by me so I can't understand it, I hope you can fix it
Message 9 of 15
ngtatsang98
in reply to: A.Acheson

I use inventor 2018 version, this code is recommended for 2017 version
Message 10 of 15
A.Acheson
in reply to: ngtatsang98

Hi @ngtatsang98 

So if I remember this forum post this code was in is about 100 messages long so this code for sure has major functionality but it really is specific to that users workflow and so is very specific. Can you edit the first post and add the forum post link to where you found the code as it is always good practice to reference the original authors.

 

If your only starting out automating drawings I would suggest to start off small and just keep it simple.

I have modified the original rule to just do the basics. You can add and modify it later if you know what the next task you need is. 

Option Explicit On
Sub Main()

	'Ask to Create Drawing
	Dim AskCreateDrawing As MsgBoxResult = MessageBox.Show("Would you like to Create Drawings for the Current Model?", "Drawing Automation",MessageBoxButtons.YesNo)
	
	'If the User Presses YES
	If AskCreateDrawing = vbYes Then
		
		'Set the View Scales
		Dim DrawingViewScale As Double = 1/10
		Dim oBaseView,oView2,oView3,oView4 As DrawingView
		Dim sAssyFileName As String = ThisDoc.FileName(False) 'without extension
		
		Dim oDrawDoc As DrawingDocument = CreateDrawing_PlaceViews (sAssyFileName, DrawingViewScale, "Right_Project", True)
		
		'Save As oDrawingDoc (Path and File Name) 
		Dim sPath As String = ThisDoc.Path

		Dim sDrawFullFileName As String = sPath & "\" & sAssyFileName & ".dwg"
			
		oDrawDoc.SaveAs(sDrawFullFileName, False)
		
	End If

End Sub

Function CreateDrawing_PlaceViews (PartNumber As String, DrawingViewScale As Double, ViewsToPlace As String, AssemblyDrawing As Boolean)

	Dim oDrawDoc As DrawingDocument
	Dim oPartDoc As Document
	Dim oSheet As Sheet
	Dim oTG As TransientGeometry
	Dim oPoint1,oPoint2,oPoint3,oPoint4 As Point2d
	Dim oBaseView,oView2,oView3,oView4 As DrawingView
	
	'If this is the Assembly View, then use this Document as reference and open Drawing Template
	'Otherwise use the given Part Number And invisibly open the part, Use the active drawing
	If AssemblyDrawing = True Then
		oPartDoc = ThisDoc.Document
		oDrawDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "C:\Users\Public\Documents\Autodesk\Inventor 2018\Templates\standard.dwg", True)
	Else If AssemblyDrawing = False 
		Dim sPartDocPath As String = ThisDoc.Path & "\" & PartNumber & ".ipt"
		oPartDoc = ThisApplication.Documents.Open(sPartDocPath, False)
		oDrawDoc = ThisApplication.ActiveDocument 
	End If
	
	oSheet = oDrawDoc.Sheets.Item(1)
	oTG = ThisApplication.TransientGeometry
	
	'Set points in order to get wanted View (ie. if 'Y' is the same and 'X' is greater or less, you will get a Side View)
	oPoint1 = oTG.CreatePoint2d(5, 5)
	oPoint2 = oTG.CreatePoint2d(5, 30)
	oPoint3 = oTG.CreatePoint2d(30, 5)
	oPoint4 = oTG.CreatePoint2d(30, 30)
	
	'Create the Base View
	oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, DrawingViewScale, kFrontViewOrientation, kHiddenLineDrawingViewStyle, "Default")
	oBaseView.ShowLabel = True
	
	'//////// Place the rest of the Projected Views According to the Parameter String Specified ////////////
	
	oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kHiddenLineDrawingViewStyle, DrawingViewScale)
	oView2.ShowLabel = True
	oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kHiddenLineDrawingViewStyle, DrawingViewScale)
	oView3.ShowLabel = True

	'Return the Drawing Document 
	Return oDrawDoc

End Function
If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 11 of 15
ngtatsang98
in reply to: A.Acheson


Your code has some errors
Error on Line 58 : 'kFrontViewOrientation' is not declared. It may be inaccessible due to its protection level.
Error on Line 58 : 'kHiddenLineDrawingViewStyle' is not declared. It may be inaccessible due to its protection level.
Error on Line 63 : 'kHiddenLineDrawingViewStyle' is not declared. It may be inaccessible due to its protection level.
Error on Line 65 : 'kHiddenLineDrawingViewStyle' is not declared. It may be inaccessible due to its protection level.

and warnings
Warning on Line 12 : Unused local variable: 'oBaseView'.
Warning on Line 12 : Unused local variable: 'oView2'.
Warning on Line 12 : Unused local variable: 'oView3'.
Warning on Line 12 : Unused local variable: 'oView4'.
Message 12 of 15
ngtatsang98
in reply to: A.Acheson

The code I found has almost no instructions, but I'm sure it does the output of the drawing fill in dimensions automatically.
this is where i found it:
https://github.com/AlexFielder/iLogic/blob/master/Drawings/Drawing%20Automation%20Code.iLogicVb
Message 13 of 15
A.Acheson
in reply to: ngtatsang98

Hi @ngtatsang98 

Just comment off this line as I was using that to better declare variables. 

'Option Explicit On

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 14 of 15
ngtatsang98
in reply to: A.Acheson

I tried again it seems to go back to the original error
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
 More info
System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.DrawingViews.AddBaseView(_Document Model, Point2d Position, Double Scale, ViewOrientationTypeEnum ViewOrientation, DrawingViewStyleEnum ViewStyle, String ModelViewName, Object ArbitraryCamera, Object AdditionalOptions)
at LmiRuleScript.CreateDrawing_PlaceViews(String PartNumber, Double DrawingViewScale, String ViewsToPlace, Boolean AssemblyDrawing)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule) 
Message 15 of 15
A.Acheson
in reply to: ngtatsang98

Hi @ngtatsang98 

Did you launch the rule from a drawing? If so the function would be supplying the drawing document to the view which of course would be wrong.

 

Here is a more simplified version of the same rule with some document checks. Also the document is supplied from one source set at the start of the rule and passed into the function as an argument. 

Sub Main()
	
	Dim oDoc As Document = ThisDoc.Document
	If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then MessageBox.Show("Not a Part/Assembly so Exiting!","Error" ) : Exit Sub 
		
	'Ask to Create Drawing
	Dim AskCreateDrawing As MsgBoxResult = MessageBox.Show("Would you like to Create Drawings for the Current Model?", "Drawing Automation",MessageBoxButtons.YesNo)
	
	'If the User Presses YES
	If Not AskCreateDrawing = vbYes Then Exit Sub 
		
	'Set the View Scales
	Dim DrawingViewScale As Double = 1/10
	Dim oBaseView,oView2,oView3,oView4 As DrawingView
	Dim sAssyFileName As String = ThisDoc.FileName(False) 'without extension

	Dim oDrawDoc As DrawingDocument = CreateDrawing_PlaceViews (oDoc, DrawingViewScale)
	
	'Save As oDrawingDoc (Path and File Name) 
	Dim sPath As String = ThisDoc.Path

	Dim sDrawFullFileName As String = sPath & "\" & sAssyFileName & ".dwg"
		
	oDrawDoc.SaveAs(sDrawFullFileName, False)
		
End Sub

Function CreateDrawing_PlaceViews (oDoc As Document, DrawingViewScale As Double)

	Dim oPoint1,oPoint2,oPoint3,oPoint4 As Point2d
	Dim oBaseView,oView2,oView3,oView4 As DrawingView
	
	Dim oDrawDoc As DrawingDocument = ThisApplication.Documents.Add(kDrawingDocumentObject, "C:\Users\Public\Documents\Autodesk\Inventor 2018\Templates\standard.dwg", True)
	Dim oSheet As Sheet = oDrawDoc.Sheets.Item(1)
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	
	'Set points in order to get wanted View (ie. if 'Y' is the same and 'X' is greater or less, you will get a Side View)
	oPoint1 = oTG.CreatePoint2d(5, 5)
	oPoint2 = oTG.CreatePoint2d(5, 30)
	oPoint3 = oTG.CreatePoint2d(30, 5)
	oPoint4 = oTG.CreatePoint2d(30, 30)
	
	'Create the Base View
	oBaseView = oSheet.DrawingViews.AddBaseView(oDoc, oPoint1, DrawingViewScale, kFrontViewOrientation, kHiddenLineDrawingViewStyle, "Default")
	oBaseView.ShowLabel = True
	
	'//////// Place the rest of the Projected Views According to the Parameter String Specified ////////////
	
	oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kHiddenLineDrawingViewStyle, DrawingViewScale)
	oView2.ShowLabel = True
	oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kHiddenLineDrawingViewStyle, DrawingViewScale)
	oView3.ShowLabel = True

	'Return the Drawing Document 
	Return oDrawDoc

End Function

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report