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

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

fitriakem
Explorer Explorer
214 Views
3 Replies
Message 1 of 4

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

fitriakem
Explorer
Explorer

Can anyone help ? I try to create drawing directly from model.

 

Imports System.IO
 
Sub Main()
 
AskCreateDrawing = MessageBox.Show("Create drawing for this Current Model?", "Create Drawing", MessageBoxButtons.YesNo)
If AskCreateDrawing = vbYes Then
 
Else
 
End If 
AskSaveModel = MessageBox.Show("Save Current Model before create drawing", "Save Model", MessageBoxButtons.YesNo)
If AskSaveModel = vbYes Then
iLogicVb.RunRule("Save")
 
End If
 
oNewDrawing = ThisDoc.ChangeExtension(".idw")
oTemplateFolder = ThisApplication.DesignProjectManager.ActiveDesignProject.TemplatesPath
 
Dim oList As New ArrayList
 
Dim Folder As New IO.DirectoryInfo(oTemplateFolder)
For Each File As IO.FileInfo In Folder.GetFiles("*.idw", IO.SearchOption.AllDirectories)
Dim sName As New FileInfo(File.Name)
oList.Add(sName.Name)
Next
 
oTemplate = InputListBox("Select a template", oList, oList(0), "iLogic", "List")
oTemplate = oTemplateFolder & oTemplate
Logger.Info(oTemplate)
Dim oDrawingDoc As DrawingDocument 
oDrawingDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, oTemplate, True)
 
End Sub
 

 

 
Imports System.IO
 
Sub Main()
 
AskCreateDrawing = MessageBox.Show("Create drawing for this Current Model?", "Create Drawing", MessageBoxButtons.YesNo)
If AskCreateDrawing = vbYes Then
 
Else
 
End If 
AskSaveModel = MessageBox.Show("Save Current Model before create drawing", "Save Model", MessageBoxButtons.YesNo)
If AskSaveModel = vbYes Then
iLogicVb.RunRule("Save")
 
End If
 
oNewDrawing = ThisDoc.ChangeExtension(".idw")
oTemplateFolder = ThisApplication.DesignProjectManager.ActiveDesignProject.TemplatesPath
 
Dim oList As New ArrayList
 
Dim Folder As New IO.DirectoryInfo(oTemplateFolder)
For Each File As IO.FileInfo In Folder.GetFiles("*.idw", IO.SearchOption.AllDirectories)
Dim sName As New FileInfo(File.Name)
oList.Add(sName.Name)
Next
 
oTemplate = InputListBox("Select a template", oList, oList(0), "iLogic", "List")
oTemplate = oTemplateFolder & oTemplate
Logger.Info(oTemplate)
Dim oDrawingDoc As DrawingDocument 
oDrawingDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, oTemplate, True)
 
End Sub
 
0 Likes
Accepted solutions (3)
215 Views
3 Replies
Replies (3)
Message 2 of 4

marcin_otręba
Advisor
Advisor
Accepted solution

hi,

 

first try to declare type of oTemplate using:

 

Dim oTemplate As String= InputListBox("Select a template", oList, oList(0), "iLogic", "List")

 

i tested your code and it works form me only if template was migrated. try to create file using template manually by clicking add new.. if it works it will work also from this code.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 4

WCrihfield
Mentor
Mentor
Accepted solution

I agree which @marcin_otręba.  It is always good practice to 'declare' (using 'Dim', or similar) all of your variables, and to also specify their Type, when possible.  This helps eliminate variable Type confusion later, and is often easier to read later also.  The main exception to when you should always initially specifying a variable's Type is when its Type may vary, or needs to change.  This is the case for the iProperty object, and the Parameter object.  Because their Value property can return varying Types, such as Double, String, Boolean, (and Date for iProperties).  I have seen many problems/errors solved by simply going back through a code and declaring every variable, and setting their Types where possible.

 

Edit:  Actually, I do see another issue in the code.  I don't think it is inserting the 'directory separator character' (usually "\") between the template folder, and the file name.  So, this

oTemplate = oTemplateFolder & oTemplate

may need to change to this:

oTemplate = oTemplateFolder & "\" & oTemplate

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 4

marcin_otręba
Advisor
Advisor
Accepted solution

i would suggest check it before if last char is  \  then

 

oTemplate = If(Right(oTemplateFolder,1)="\",oTemplateFolder,oTemplateFolder=oTemplateFolder & "\") & oTemplate

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes