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
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.
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)
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"
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)
You have a string error in
String "DimensionLocation" but I am not sure why it is saying in part5.ipt.
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
Hi @ngtatsang98
Just comment off this line as I was using that to better declare variables.
'Option Explicit On
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
Can't find what you're looking for? Ask the community or share your knowledge.