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: 

iLogic -The Parameter is incorrect error

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
2058 Views, 4 Replies

iLogic -The Parameter is incorrect error

Trying to open an Excel list of parts from an Excel File (QTY  PART columns) Open the part, update the QTY then close the Part. It works fine through the first pass then I get an "The Parameter is incorrect error". Can anyone tell me Why?

 

Thanks

4 REPLIES 4
Message 2 of 5
Owner2229
in reply to: Anonymous

Hey, it's because with every loop you're changing "oPartFullPath":

 

oPartFullPath = oPartFullPath + "\" + oPartFull

 

So on second loop it does this:

oPartFullPath = oPartFullPath + "\" + oPartFull + "\" + oPartFull

 

Also, don't use "+" for string, use "&" instead.

 

Here's the correction and some simplification:

 

Dim oPartFullPath As String = ThisDoc.Path
Dim oExcelFile As String = oPartFullPath & "\178150.xls"

GoExcel.Open(oExcelFile, "Sheet1") For i As Integer = 3 To 6 Dim oPart As String = GoExcel.CellValue("B" & CStr(i)).ToString & ".ipt" Dim oTQTY As Integer = Convert.ToInt32(GoExcel.CellValue("A" & CStr(i))) Dim oPath As String = oPartFullPath & "\" & oPart Dim xDoc As Document = ThisApplication.Documents.Open(oPath, True) 'False = open invisible iProperties.Value("Custom", "TQTY") = oTQTY InventorVb.DocumentUpdate() xDoc.Save xDoc.Close(True) MessageBox.Show(i, "Number of Passes Completed") Next
GoExcel.Close(True)
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 5
Anonymous
in reply to: Anonymous

Thanks.

Sometimes you can't see the forest for the trees. The last problem is at the end of the loop it crashed due to a Blank at the end of the list.

I added a goto statement

If i = 230 (Then end of the list +1) then Goto 100

 

100:

MessageBox.Show(i, "Number of Parts Updated")

 

It doesn't like i now. If I change it to "230" as a test it works fine.

Why does the counter i cause it to Error?

 

Error is

Rule Compile Errors in Part TQTY, in PL1.ipt

Error on Line 34 : Variable 'i' hides a variable in an enclosing block.

 

 

Line 34 is  For i As Integer = 220 To 230

 

 

Thanks

Message 4 of 5
Owner2229
in reply to: Anonymous


steve wrote:

Sometimes you can't see the forest for the trees.


That's so true.

 

What is says is that you're declaring the variable "i" twice. Use "j" or something else.

 

If you want to skip some specific numbers you can do it like this:

 

For i = 220 To 230
     If i = 230 Then Continue For
Next

Also, if you want the code to be "crash proff" use "Try Catch". Here's the code updated:

 

Dim oPartFullPath As String = ThisDoc.Path
Dim oExcelFile As String = oPartFullPath & "\178150.xls"

GoExcel.Open(oExcelFile, "Sheet1")
For i As Integer = 3 To 6
     Try
          Dim oPart As String = GoExcel.CellValue("B" & CStr(i)).ToString & ".ipt"
          Dim oTQTY As Integer = Convert.ToInt32(GoExcel.CellValue("A" & CStr(i)))
          Dim oPath As String = oPartFullPath & "\" & oPart
          Dim xDoc As Document = ThisApplication.Documents.Open(oPath, True) 'False = open invisible
          iProperties.Value("Custom", "TQTY") = oTQTY
          InventorVb.DocumentUpdate()
          xDoc.Save
          xDoc.Close(True)
          MessageBox.Show(i, "Number of Passes Completed")
     Catch
     End Try
Next
GoExcel.Close(True)
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 5 of 5
Anonymous
in reply to: Owner2229

I am searching for the VBA program for the slicing tool which will work as automatic 2D sketch generator for every  cross section view from the 3D object. Luckily found the similar tool on YouTube (https://www.youtube.com/watch?v=hefY46fyVvU) but whenever I run the program its shows me the error of "The Parameter is incorrect" and "Run time error70". I also tried to connect with the creator of that Slicer Tool but he/she wont use Inventor anymore. 

Sharing the VBA file which I am using  for generating this tool, its only RUN in inventor. If its work for anyone please help me, its my first time of using VBA in Inventor. 

 

'ClsToolbarEvents: 

 

Public BasePlane As Object
Private WithEvents m_BasePlane As MiniToolbarButton
Private WithEvents m_Thickness As MiniToolbarValueEditor
Private m_BasePlaneName As MiniToolbarControl
Private WithEvents m_MiniToolbar As MiniToolbar
Private bStop As Boolean

Public Sub Init(oMiniToolbar As MiniToolbar)
Set m_MiniToolbar = oMiniToolbar
Set m_BasePlane = m_MiniToolbar.Controls.Item("btnBasePlane")
Set m_Thickness = m_MiniToolbar.Controls.Item("Thickness")
Set m_BasePlaneName = m_MiniToolbar.Controls.Item("lblBasePlane")
m_MiniToolbar.EnableOK = False
bStop = False

Do
ThisApplication.UserInterfaceManager.DoEvents
Loop Until bStop

End Sub

Private Sub m_BasePlane_OnClick()
Set BasePlane = ThisApplication.CommandManager.Pick(kAllPlanarEntities, "Select start plane or face")
If BasePlane Is Nothing Then Exit Sub
If TypeName(BasePlane) = "WorkPlane" Then
m_BasePlaneName.DisplayName = BasePlane.Name
Else
m_BasePlaneName.DisplayName = BasePlane.Parent.Name & ".Face"
End If
m_MiniToolbar.EnableOK = True
End Sub

Private Sub m_BasePlane_OnClick()
Set BasePlane = ThisApplication.CommandManager.Pick(kAllPlanarEntities, "Select start plane or face")
If BasePlane Is Nothing Then Exit Sub
If TypeName(BasePlane) = "WorkPlane" Then
m_BasePlaneName.DisplayName = BasePlane.Name
Else
m_BasePlaneName.DisplayName = BasePlane.Parent.Name & ".Face"
End If
m_MiniToolbar.EnableOK = True
End Sub

Private Sub m_MiniToolbar_OnCancel()
bStop = True
End Sub


Private Sub m_MiniToolbar_OnOK()
SliceIt
End Sub

 

Private Sub SliceIt()

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oDef As PartComponentDefinition
Set oDef = oDoc.ComponentDefinition
Dim oSketch As PlanarSketch

Dim P As profile
Dim PP As ProfilePath
Dim nWP As WorkPlane
Dim i As Long
Dim SVG As New SVGFile
Dim ErrCount As Integer

Dim originX As Double, originY As Double
Dim P1 As Point2d, P2 As Point2d

Dim offset As Double, delta As Double
offset = 0
delta = m_Thickness.Expression / 10000

Set nWP = oDef.WorkPlanes.AddByPlaneAndOffset(BasePlane, delta)
Set oSketch = oDef.Sketches.Add(nWP, False)

'find model exxtents in the slice plane
Set P1 = oSketch.ModelToSketchSpace(oDef.RangeBox.MaxPoint)
Set P2 = oSketch.ModelToSketchSpace(oDef.RangeBox.MinPoint)
SVG.OpenFile (P1.X + P2.X) / 2, (P1.Y + P2.Y) / 2

'check the extrude direction
On Error Resume Next
oSketch.ProjectedCuts.Add
If Err <> 0 Then
delta = -delta
End If
'And now extrude
ErrCount = 0
While Not bStop
nWP.SetByPlaneAndOffset BasePlane, offset
Set oSketch = oDef.Sketches.Add(nWP, False)
On Error Resume Next
oSketch.ProjectedCuts.Add
oSketch.Profiles.AddForSolid
On Error GoTo 0

If oSketch.Profiles.count = 0 Then
ErrCount = ErrCount + 1
If ErrCount > 3 Then
nWP.Delete
bStop = True
SVG.finish
Exit Sub
End If
Else
DoEvents
SVG.Add_Layer (offset)
For Each P In oSketch.Profiles
For Each PP In P
SVG.Add_Profile PP
Set PP = Nothing
Next
Set P = Nothing
Next
End If
oSketch.Delete
Set oSketch = Nothing
offset = offset + delta
Wend
bStop = True
SVG.finish
End Sub

 

'MODULE 1:

Public Sub SliceToSVG()
Dim oActiveEnv As Environment
Set oActiveEnv = ThisApplication.UserInterfaceManager.ActiveEnvironment

If oActiveEnv.InternalName <> "PMxPartEnvironment" Then
MsgBox "This command can only run in an isolated part context (at the moment at least)"
Exit Sub
End If

Dim oMiniToolbar As MiniToolbar
Set oMiniToolbar = ThisApplication.CommandManager.CreateMiniToolbar

oMiniToolbar.ShowOK = True
oMiniToolbar.ShowApply = False
oMiniToolbar.ShowCancel = True

Dim oControls As MiniToolbarControls
Set oControls = oMiniToolbar.Controls
oControls.Item("MTB_Options").Visible = False

Dim oDescriptionLabel As MiniToolbarControl
Set oDescriptionLabel = oControls.AddLabel("Description", "Slice the part to SVG", "The intention is to drive a DLP")
oControls.AddNewLine

Dim oPlaneChooser As MiniToolbarButton
Set oPlaneChooser = oControls.AddButton("btnBasePlane", "Base Plane:", "Pick the base plane to slice parallel to")

Dim oPlaneName As MiniToolbarControl
Set PlaneName = oControls.AddLabel("lblBasePlane", " ", "Press the button on the left to choose a plane")

oControls.AddNewLine

Dim oSliceThickness As MiniToolbarValueEditor
Set oSliceThickness = oControls.AddValueEditor("Thickness", "Enter slice thickness (microns)", kLengthUnits, "microns")
oSliceThickness.Expression = "50"


' Set the position of mini-toolbar
Dim oPosition As Point2d
Set oPosition = ThisApplication.TransientGeometry.CreatePoint2d(ThisApplication.ActiveView.Left, ThisApplication.ActiveView.Top)
oMiniToolbar.Position = oPosition

oMiniToolbar.Visible = True

Dim oMiniToolbarEvents As New ClsToolbarEvents

Call oMiniToolbarEvents.Init(oMiniToolbar)

End Sub

 

'slicer:

Dim ts As Scripting.TextStream
Dim fs As New Scripting.FileSystemObject
Dim indent As Integer
Dim path As Long, layer As Long
Dim CurrentLayer As String
Dim CurrentPath As String
Const PI As Double = 3.14159265358979
Const rad2deg As Double = 180 / 3.14159265358979

Const height As Double = 21
Const width As Double = 27.9
Const scalefac As Double = 1

Sub OpenFile(originX As Double, originY As Double)
Set ts = fs.CreateTextFile("D:/PYTHON/STL file/newfile.svg")
writelineTS "<?xml version='1.0' encoding='UTF-8' standalone='no'?>"
writelineTS "<svg"
writelineTS "xmlns='http://www.w3.org/2000/svg'"
writelineTS "xmlns:inkscape='http://www.inkscape.org/namespaces/inkscape'"
writelineTS "xmlns:slicer='http://www.bodgesoc.org'"
writelineTS "width='{1}cm'", width
writelineTS "height='{1}cm'", height
writelineTS "viewBox='{1} {2} {3} {4}'", -(width / 2), -height / 2, width, height
writelineTS "version='1.1'"
writelineTS "style='fill:#ffffff;fill-rule:evenodd;stroke-width:0px;fill-opacity:1' >"
writelineTS "<rect style='fill:#000000;fill-opacity:1;stroke:none' width='100%' height='100%' x='{1}' y='{2}' />", -width / 2, -height / 2
writelineTS "<g transform='translate({1},{2}) scale({3}, {4})'>", -originX, originY, scalefac, -scalefac
End Sub


Sub Add_Layer(offset As Double)
If CurrentLayer <> "" Then
writelineTS "</g>"
CurrentLayer = ""
End If

layer = layer + 1
CurrentLayer = "layer_" & layer
writelineTS "<g inkscape:groupmode='layer' inkscape:label='{1}' ", CurrentLayer
writelineTS "id='{1}' slicer:Z='{2}' >", CurrentLayer, Abs(offset * 10)
End Sub

Sub finish()
Dim oFileDlg As FileDialog
Dim fname As String
If CurrentLayer <> "" Then
writelineTS "</g>"
CurrentLayer = ""
End If
writelineTS "</g>" ' Close the transform group
ts.WriteLine "</svg>"
ts.Close

Call ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "SVG File (*.svg)"
oFileDlg.DialogTitle = "Choose a filename"
oFileDlg.InitialDirectory = "D:\PYTHON\STL file"
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowSave
If Not Err Then
fname = oFileDlg.FileName
If fs.GetExtensionName(fname) <> "svg" Then fname = fname & ".svg"
fs.CopyFile "D:\PYTHON\STL file\newfile.svg", fname, True
fs.DeleteFile "D:\PYTHON\STL file\newfile.svg"
End If
On Error GoTo 0
bStop = True
End Sub

Private Sub openpath(startx As Double, starty As Double)

If CurrentPath <> "" Then Exit Sub

path = path + 1
CurrentPath = "path_" & path
writelineTS "<path id='{1}'", CurrentPath
writeTS "d='M {1} {2} ", startx, starty

End Sub


Private Sub closepath(profile As ProfilePath)
If CurrentPath = "" Then Exit Sub
CurrentPath = ""
writeTS " Z'"
If profile.AddsMaterial = False Then writeTS " style='fill:#000000' "
writelineTS " />"
End Sub


Private Function writeTS(f As String, ParamArray t())
' A simple version of printf for putting numbers into strings
' also replaces ' by "" to keep things legible
Dim i As Integer
For i = 0 To UBound(t)
f = Replace$(f, "{" & i + 1 & "}", t(i))
Next
f = Replace$(f, "'", """")
If InStr(f, "</g>") Then
indent = indent - 3
End If
ts.Write f
If ts.Column > 120 Then
ts.WriteLine
ts.Write Space(indent)
End If
If InStr(f, "<g") Or InStr(f, "<svg") Then
indent = indent + 3
End If
End Function


Private Function writelineTS(f As String, ParamArray t())
' A simple version of printf for putting numbers into strings
' also replaces ' by "" to keep things legible
Dim i As Integer
For i = 0 To UBound(t)
f = Replace$(f, "{" & i + 1 & "}", t(i))
Next
f = Replace$(f, "'", """")
If InStr(f, "</g>") Then
indent = indent - 3
End If
ts.WriteLine f

If InStr(f, "<g") Or InStr(f, "<svg") Then
indent = indent + 3
End If
ts.Write Space(indent)
End Function

Function ArcTan2(X As Double, Y As Double) As Double
Select Case X
Case Is > 0
ArcTan2 = Atn(Y / X)
Case Is < 0
ArcTan2 = Atn(Y / X) + PI * Sgn(Y)
If Y = 0 Then ArcTan2 = ArcTan2 + PI
Case Is = 0
ArcTan2 = PI / 2 * Sgn(Y)
End Select
End Function

 

 

 

 

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

Post to forums  

Autodesk Design & Make Report