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 code only works on certain computers

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
437 Views, 9 Replies

iLogic code only works on certain computers

Hi,

 

A couple years ago, I created an iLogic code to modify the view label description in a drawing.  It basically looks at the label of the last view and takes the label name along with a project iproperty and sheet number and sends that back to the status iproperty to the part.  I then use this status iproperty in the view label and it is also used in the BOM to describe where to find a certain part in a drawing set.  For some reason this has always worked fine on my machine but not on everyone elses machine.  We did have one machine that the code just wouldn't work.  It didn't give any errors, but didn't seem to do anything either.  We fixed it by setting it up as an external rule, and for some reason the external rule would work when it was ran.  We have now replaced that machine and another and reinstalled Inventor 2015, and now the rule will not work when it is embedded in a drawing and also will not work when used as an external rule either.  The machine is basically the same as mine, they are both an HP Z420 with Xeon E5-1607 processors and 32 GB of RAM.  The code is below, I'd really appreciate it if someone had some insight as to why this might not work on both machines.  I'm certainly not a programmer, I found similar codes online and modified them to do what we needed it to.

 

Here is the code:

 

'start of ilogic code
Dim oDoc As DrawingDocument: oDoc = ThisDoc.Document
Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
Dim SheetNumber As String
i =1
oSheets = oDoc.Sheets

For Each oSheet In oSheets
oViews = oSheet.DrawingViews
For Each oView In oViews
'capture the current view label
ViewLabel = oView.Name
'reset the display name
oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName = ""
'get the display name
oModelName = _
oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
Try
'get the sheet number
SheetNumber =Mid(oSheet.Name, InStr(1, oSheet.Name, ":") + 1)
i=1+1
iProperties.Value(oModelName, "Status", "Status") = _
iProperties.Value("Project", "Project")+"-"+ViewLabel+SheetNumber
'Send view label items to models Status iProperty
'Use Status iProperty for view label
Catch
'do nothing if error
End Try
Next
iLogicVb.UpdateWhenDone = True
Next
'end of ilogic code

9 REPLIES 9
Message 2 of 10
Curtis_Waguespack
in reply to: Anonymous

 

Hi jestes,

I'm not sure what would be at play, but one thing I did notice:

 

There is a Try/Catch in this rule that basically skips over any errors it encounters at that point. In the modified version below, the 'do nothing if error line has been replaced by a line reading MessageBox.Show("There is an ERROR here!.", "iLogic").

 

You might try running this version, just to see if there are some errors that are be skipped over, making it seem like the rule is not running.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'start of ilogic code
Dim oDoc As DrawingDocument: oDoc = ThisDoc.Document
Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
Dim SheetNumber As String
i =1
oSheets = oDoc.Sheets

For Each oSheet In oSheets
oViews = oSheet.DrawingViews
For Each oView In oViews
'capture the current view label
ViewLabel = oView.Name
'reset the display name
oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName = ""
'get the display name
oModelName = _
oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
Try
'get the sheet number
SheetNumber =Mid(oSheet.Name, InStr(1, oSheet.Name, ":") + 1)
i=1+1
iProperties.Value(oModelName, "Status", "Status") = _
iProperties.Value("Project", "Project")+"-"+ViewLabel+SheetNumber
'Send view label items to models Status iProperty
'Use Status iProperty for view label
Catch
MessageBox.Show("There is an ERROR here!.", "iLogic")
End Try
Next
iLogicVb.UpdateWhenDone = True
Next
'end of ilogic code

 

Message 3 of 10
Anonymous
in reply to: Curtis_Waguespack

Thanks for the response.  There are many errors.  On the machine that is having trouble it seems like every view in the drawing gives an error as it runs through them but I'm not sure why.  On my machine the only views that give me errors are the assembly views that are not in the master level of detail.  I can live with that because it's mainly the single part details that I need this for.  I know it doesn't work with iparts either but we don't use many of them.  So I guess that's why it's not working, there is just some sort of error but I don't know what it is or why it would be different than mine.  Is there a way to get it to give any details about the error or show where it is in the code?

Message 4 of 10
Anonymous
in reply to: Curtis_Waguespack

I have played with this code a bit on the machines that will not run it without errors and have narrowed the errors down to a couple lines, but I'm not sure why they are not working.  I have highlighted the two lines in red in the program below.  If they are commented out, the program runs without errors, but doesn't really do much because those are the two lines that assign the value to the iproperty that I'm using.  Any ideas what would be wrong that would throw an error in that section?  Thanks for the help.

 

'start of ilogic code
Dim oDoc As DrawingDocument: oDoc = ThisDoc.Document
Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
Dim SheetNumber As String
i =1
oSheets = oDoc.Sheets

For Each oSheet In oSheets
oViews = oSheet.DrawingViews
For Each oView In oViews
'capture the current view label
ViewLabel = oView.Name
'reset the display name
oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName = ""
'get the display name
oModelName = _
oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
Try
'get the sheet number
SheetNumber =Mid(oSheet.Name, InStr(1, oSheet.Name, ":") + 1)
i=1+1
iProperties.Value(oModelName, "Status", "Status") = _
iProperties.Value("Project", "Project")+"-"+ViewLabel+SheetNumber
'Send view label items to models Status iProperty
'Use Status iProperty for view label
Catch
MessageBox.Show("There is an ERROR here!.", "iLogic")
End Try
Next
iLogicVb.UpdateWhenDone = True
Next

Message 5 of 10
philippe.leefsma
in reply to: Anonymous

My first guess would be that your property value is set with some specific characters which are unsupported. But do you mean that it fails only on some computers and works fine on some others?

 

Is the string machine-dependent? Did you try to replace the property value by a simple static string that is proven to work everywhere?

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 6 of 10
Anonymous
in reply to: philippe.leefsma

Philippe,

 

Thanks for the reply.  I've done some more testing on this code on my machine and the others that will not run it, and have narrowed down exactly what part isn't working, but I haven't figured out why.  I thought that the oModelName definition line might be the problem, so I commented out the rest and added a line that printed oModelName for each view, and that worked fine on all machines.

 

It seems like the other machines that won't work have an issue sending iproperties from the drawing to a model referenced in the view.  The code below is the issue even after verifying that oModelName is correct. 

 

iProperties.Value(oModelName, "Status", "Status") = _
        iProperties.Value("Project", "Project")+"-"+ViewLabel+SheetNumber

 

I even replaced oModelName with the actual file name of the model and that didn't go through either.  I also changed the code as shown below with no success either, but all of it works fine on my machine, just not on a couple others for some reason.

 

iProperties.Value(oModelName, "Status", "Status") = "2"
       

I also tried sending the value to a different iProperty such as part number, but still couldn't get it to work.

 

On the machines that will not run the code, I tried sending something to an iProperty in the drawing itself, and that works fine.  It just won't send it to the model iProperties from the drawing.  I don't really know what to try next, I had thought of just doing a re-install when we get time on those machines to see if it fixes it.  Are there any files that could be corrupt that I could copy from my machine to another?  Are there any other ways of addressing the iProperty of the model that might work differently?

 

Thanks for the help,

Jeremy

Message 7 of 10
rjay75
in reply to: Anonymous

Check to make sure the model files are not read only or in a readonly directory when they are opened on the machines that are failing.

Message 8 of 10
Anonymous
in reply to: rjay75

I checked the files and they aren't read only.  Also, we can run the rule in a drawing on one machine and it won't work, and then immediately run the rule on the exact same drawing on my machine and it will work fine.

Message 9 of 10
philippe.leefsma
in reply to: Anonymous

Without being able to reproduce the behavior on our side, it is difficult to diagnose the issue. What you could try next is to use the Inventor API, either from iLogic (you can use VB.Net syntax in iLogic rather than the higher level wrappers) or directly from a VB.Net executable.

 

There is a dedicated section in the API Help Files:

 

iproperties.png

 

Also you can find samples in our online Inventor Training Material (see Module 2 for iProperties samples).

 

Hope that helps,

Philippe.

 

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 10 of 10
Anonymous
in reply to: philippe.leefsma

Thanks,

 

I understand it's very difficult to diagnose a problem you can't see yourself.  We actually got it working I think, time will tell.  We had tried running the code as an external rule, and that didn't work, but we had a .txt extension.  We resaved the file with a .iLogicvb extension and it seems to work when running as an external rule.  I'm not sure why this would make any difference or why it wouldn't run when embedded in the drawing document but hopefully this will work. 

 

Thanks for the help.

Jeremy

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

Post to forums  

Autodesk Design & Make Report