iLogic error - Can't find the reason

iLogic error - Can't find the reason

ChristianAndersenIsmyname
Advocate Advocate
1,497 Views
13 Replies
Message 1 of 14

iLogic error - Can't find the reason

ChristianAndersenIsmyname
Advocate
Advocate

Hello, I'm completly new and still trying to learn iLogic and coding in general.

I have code that makes a drawing of my open part/assembly, which I found here: https://clintbrown.co.uk/2018/10/07/automatic-drawings-with-ilogic/

 

I've edited the code to match my file locations and template names, but I'm getting a error that I can't understand.

ChristianAndersenIsmyname_0-1594821550075.png

File Locations:

ChristianAndersenIsmyname_1-1594821673382.png

 

 

The code I'm using (with minor edits as explained above).

'Check if this is a drawing file
Dim doc = ThisDoc.Document
If doc.DocumentType = kDrawingDocumentObject Then
GoTo DRAWINGcode :
End If

'In parts & asemblies - Write file name and path to temp text file
oWrite = System.IO.File.CreateText("C:\TEMP\part.txt")
oWrite.WriteLine(ThisDoc.PathAndFileName(True))
oWrite.Close()
oFilePather = ThisDoc.Path & "\"

'In parts & asemblies - Write new drawing name to temp text file
oWrite = System.IO.File.CreateText("C:\TEMP\partno.txt")
oWrite.WriteLine(oFilePather & iProperties.Value("Project", "Part Number") & ".dwg")
oWrite.Close()

'Read Drawing name from text file
oRead = System.IO.File.OpenText("C:\TEMP\partno.txt")
EntireFile1 = oRead.ReadLine()
oRead.Close()
oDrawingName = EntireFile1

'Copy the Template file > keep templates saved in your project workspace, you need a separate part and assembly template
Dim oCopyFiler As String = "www.clintbrown.co.uk"
If doc.DocumentType = kAssemblyDocumentObject Then
oCopyFiler = "<u+202a>K:\04. R&amp; teD\3D MODELING\STYLES\Templates\Stject woandard.idw"
Else If doc.DocumentType = kPartDocumentObject Then
oCopyFiler = "<u+202a>K:\04. Rtemplat&amp;d.idw"
ElsD\3D MODELING\STYLES\Templates\Spacer_template.idw"
End If

' Check if drawing exists - If it does, opening existing drawing
If System.IO.File.Exists(oDrawingName pe = kA&amp;MOD DWGType) Then
MessageBox.Show("Drawing already exists  If

' >gt;Type Opening Existing Drawing", "@ClintBrown3D")
ThisDoc.Launch(oDrawingName awing e&amp;ing DWGType)
Return
End If

'Launch New drawing
Dim oNewFiler As String = EntireFile1
System.IO.File.Copy(oCopyFiler,oNewFiler,(True))
ThisDoc.Launch(oNewFiler)

DRAWINGcode :
On Error GoTo Exiter
'Check if we have replaced the reference and scaled the drawing already
oNumbero = Parameter("Opened")
Parameter("Opened") = oNumbero + 1
'MsgBox(Parameter("Opened"))
If Parameter("Opened") > 2 Then
Return
End If

'Read in File name - For reference
oRead = System.IO.File.OpenText("C:\TEMP\part.txt")
EntireFile = oRead.ReadLine()
oRead.Close()
oPartPath = EntireFile

'Replace Drawing Reference
doc = ThisDoc.Document
Dim oFileDesc As FileDescriptor
oFileDesc = doc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
oFileDesc.ReplaceReference(oPartPath)
doc.Update()

'Read in new name for Drawing
oRead = System.IO.File.OpenText("C:\TEMP\partno.txt")
EntireFile1 = oRead.ReadLine()
oRead.Close()
oDrawingName = EntireFile1

'Save this drawing
ThisDoc.Save

'Scale the Drawing - Note your drawing views names("VIEW1")&("VIEW4") must match the template
On Error GoTo Exiter
oMyParameter = ThisDrawing.Document.Parameters.UserParameters
oParameter = oMyParameter.AddByValue("Scaler", "1:5", UnitsTypeEnum.kTextUnits)
MultiValue.SetList("Scaler","1:1", "1:2", "1:4", "1:5", "1:10", "1:20", "1:25", "1:50", "1:100")

Scaler = InputListBox("Set Drawing Scale", MultiValue.List("Scaler"), Scaler, Title := "Scale = " & ActiveSheet.View("VIEW1").ScaleString, ListName := "List")
ActiveSheet.View("VIEW1").ScaleString = Scaler
ActiveSheet.View("VIEW4").ScaleString = Scaler
Parameter.Param("Scaler").Delete

Exiter :
'Msgbox("Scale not Changed")

 

Can anyone see what causes this error?

Thanks

0 Likes
1,498 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable

Based on your error, the issue is here. One of your paths is invalid

 

System.IO.File.Copy(oCopyFiler,oNewFiler,(True))

 

Your oCopyFilers looks fine from what I can see, but oNewFiler is based on iproperties. Do your iproperties contain any invalid characters for a file path?  Also you looks like you are copying an .idw to a .dwg, but I'm not sure if that is an issue or not.

Message 3 of 14

WCrihfield
Mentor
Mentor

Has the active document been saved yet, before running this rule?  If not, trying to access its path and file name with cause errors.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 14

ChristianAndersenIsmyname
Advocate
Advocate

Both yes and no, getting the same errors regardless if its been saved.

 

I thought this code here made sure it doesnt matter if its beens saved yet, cause it makes a temp file?

'In parts & asemblies - Write file name and path to temp text file
oWrite = System.IO.File.CreateText("C:\TEMP\part.txt")
oWrite.WriteLine(ThisDoc.PathAndFileName(True))
oWrite.Close()
oFilePather = ThisDoc.Path & "\"

 

0 Likes
Message 5 of 14

ChristianAndersenIsmyname
Advocate
Advocate

It seems like the dwg is the issue here.

Is it possible to rewrite the code to use idw instead, if so, how can I do that?

0 Likes
Message 6 of 14

Anonymous
Not applicable

I think you should just be able to replace

oWrite.WriteLine(oFilePather & iProperties.Value("Project", "Part Number") & ".dwg")

with

oWrite.WriteLine(oFilePather & iProperties.Value("Project", "Part Number") & ".idw")

 unless there is something I'm missing

Message 7 of 14

ChristianAndersenIsmyname
Advocate
Advocate

I have no idea whats happening anymore.

If I make a new part from the template, I'll get this error.

ChristianAndersenIsmyname_1-1594825763225.png

 

But if I save the part, it opens the template idw (with reference to template ipt).

 

I'm not sure if this is one step closer or not, hehe.

0 Likes
Message 8 of 14

Anonymous
Not applicable

Well it looks like an extra backslash is in one of your paths. Can you add a Msgbox before your copy so we can see what the paths are? Something like this

 

 

MsgBox(oCopyFiler & vbNewLine & oNewFiler)

Dim oNewFiler As String = EntireFile1
System.IO.File.Copy(oCopyFiler,oNewFiler,(True))
ThisDoc.Launch(oNewFiler)

 

 

 

Message 9 of 14

ChristianAndersenIsmyname
Advocate
Advocate

That also fails for some reason.

 

I have it in norwegian, so instead of a screenshot I'll try to translate:

 

Line 20, 30 and 33: Can't refer to the local variable oCopyFiler until it's been declared.

Line 32 and 51: The local variable oNewFiler is already been declared in active block.

 

0 Likes
Message 10 of 14

Anonymous
Not applicable

My bad, you need to put after you define oNewFiler but before you try to copy. And to make sure, you are replacing your current copy code and not adding it a second time right?

 

Dim oNewFiler As String = EntireFile1

MsgBox(oCopyFiler & vbNewLine & oNewFiler)

System.IO.File.Copy(oCopyFiler,oNewFiler,(True))
ThisDoc.Launch(oNewFiler)

 

Message 11 of 14

ChristianAndersenIsmyname
Advocate
Advocate

Now the message box appears, but still getting the same "path '\.idw' is denied."

 

ChristianAndersenIsmyname_1-1594828891862.png

 

0 Likes
Message 12 of 14

Anonymous
Not applicable

So the problem is coming from

 

oWrite.WriteLine(oFilePather & iProperties.Value("Project", "Part Number") & ".idw")

 

 oNewFiler equals "\.idw" because both oFilePather and iProperties.Value("Project", "Part Number") equal nothing so "/.idw" is all that's left.

 

oFilePather comes from

 

oFilePather = ThisDoc.Path & "\"

 

Which means ThisDoc.Path is returning nothing. I'm not sure why, but it could be as @WCrihfield mentioned and it's because the document hasn't been saved yet so it has no permanent path.

 

iProperties.Value("Project", "Part Number") is empty because you haven't assigned your document a Part Number in the Project tab in iProperties

Message 13 of 14

ChristianAndersenIsmyname
Advocate
Advocate

I found out that I forgot 1 step that Clint said. "In this new drawing file Next, set up an Event trigger to run “After Open Document” and use the new “Create Drawing” external iLogic Rule", I thought this was only for the .ipt.

So now it opens the correct template.

 

Replacemodel.png

But.. it doesnt replace the model to my new one.

Note that the drawing is named "Part12", while model in the view is "Spacer.ipt" (the template).

0 Likes
Message 14 of 14

Anonymous
Not applicable

If you're are getting through the entire code without any errors, but it's still not working as intended, it could have to with how you have set up your documents/rules. I'm not sure I can help you with that, but there was a link at the bottom of the post where you got this code for additional help, you may have already seen it though. Here