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: 

Exception from HRESULT: 0x80070057 (E_INVALIDARG)

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
Anonymous
5346 Views, 9 Replies

Exception from HRESULT: 0x80070057 (E_INVALIDARG)

I made a iLogic form with multiple rules to automate the drawing proces for sheet metal parts. The drawing engineer only quickly has to place folded model views of all his sheet metal parts and apply some rules.  It consist of the following rules;

 

I first have to explain what i am doing before I can tell the problem, so;

Please see the attached image 1 to see the wanted result (left sheet metal view) and the unwanted result (right sheet metal view)

 

  1. The first rule changes the folded view to a flat pattern view with the following piece of code
    1.  
    2. Dim oDoc As Document = ThisApplication.ActiveDocument
      If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
      
      Dim oView As DrawingView
      Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
      If oSSet.count = 0 Then
           MessageBox.Show("Select view(s)", "Attention!")
           Exit Sub
      End If
      
      Dim oSheet As Sheet = oDoc.ActiveSheet
      
      	For Each oView In oSSet
          	 Dim oModel As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
          	 If oModel.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For
          	 Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
          	 oOptions.Add("SheetMetalFoldedModel", False)
         		 Dim oPoint As Point2D = oView.Position
           	 Dim oViewStyle As DrawingViewStyleEnum = oView.ViewStyle
           	 Dim oScale As Double = oView.Scale
           	 Dim oOri As ViewOrientationTypeEnum = ViewOrientationTypeEnum.kDefaultViewOrientation
           	 oSheet.DrawingViews.AddBaseView(oModel, oPoint, oScale, oOri, oViewStyle, , , oOptions)
           	 oView.Delete()
      	Next
  2. The second rule changes the scale of all the selected views to a desired scale with the following piece of code;
    1. Dim oDoc As DrawingDocument = ThisDoc.Document
      oModel = ThisDoc.ModelDocument
      
      Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
      If oSSet.count = 0 Then
      	MessageBox.Show("View(s) selecteren", "Let op")
      Exit Sub
      End If
      
      Dim oViews As DrawingViews
      Dim oView As DrawingView
      
          For Each oView In oSSet
          oView.Scale = "0,2"
      Next
  3.  The third rule places a custom view label to each selected view with the following piece of code;

 

'start of ilogic code
'specify font 
sFont = "Arial"
sFSize1 = 0.18 'font size in cm
sFSize2 = 0.30 'font size in cm
sFSize3 = 0.25
sFSize4 = 0.10

'Part Number
sString1 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize2 & "' Bold='True'>" _
& "<Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' " &  _
"FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>Part Number</Property></StyleOverride>"

'Scale
sString2 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "'> (SCALE: </StyleOverride>"
sString3 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "'>" & _
"<DrawingViewScale/>)</StyleOverride>"

'Type 
sString4 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize3 & "'>TYPE: </StyleOverride>"
sString5 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize2 & "' Bold='True'>" _
& "<Property Document='model' PropertySet='User Defined Properties' Property='TEKST PLAAT' " & _
"FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' >TEKST PLAAT</Property> </StyleOverride>"

'Dikte
sString6 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize2 & "' Bold='True'>" _
& "<Property Document='model' PropertySet='User Defined Properties' Property='DIKTE' " & _
"FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' >DIKTE</Property></StyleOverride>"
sString7 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize3 & "' Bold='True'> mm </StyleOverride>"

'Materiaal
sString8 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize2 & "' Bold='True'>" _
& "<Property Document='model' PropertySet='User Defined Properties' Property='MATERIAL' " & _
"FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' >MATERIAL</Property>  </StyleOverride>"

'Aantal
sString9 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize3 & "' >AANTAL: </StyleOverride>"
sString10 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize2 & "' Bold='True'>" _
& "<Property Document='model' PropertySet='User Defined Properties' Property='PartQty' " & _
"FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' >PartQty</Property>  </StyleOverride>"



Dim oDoc As DrawingDocument = ThisDoc.Document
oModel = ThisDoc.ModelDocument

Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
If oSSet.count = 0 Then
	MessageBox.Show("View(s) selecteren", "Let op")
Exit Sub
End If

Dim oViews As DrawingViews
Dim oView As DrawingView

    For Each oView In oSSet
    
	'make view label visible
    oView.ShowLabel = True
    
    'add lines to the view label
    'break line using:  "<Br/>" 
    oView.Label.FormattedText = _
    sString1 & "<Br/>" & _
	sString2 & sString3 & "<Br/>" & _
	sString4 & sString5 & sString6 & sString7 & sString8 & sString9 & sString10
Next

 

For some reason, some of the selected views give me a error while the parts are build the exact same way...

Please see image 2 and 3 for the error code i am getting. 

 

One more important thing. When i get this error code with one of my selected views, i can open the part and then return to my drawing and retry the iLogic code which result in a succes.

 

Many thanks in advance to the person who can help me :)!

 

 

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

Hey, I've made some adjustments to your code and tested it and it seems to work properly.

Orange highlighted is the error catch. The rest is just a little simplification. Using subs/functions for repeated operations is better, space saving and clearer.

 

Sub Main()
Dim sFont As String = "Arial"
Dim sFSize1 As Double = 0.18 'font size in cm
Dim sFSize2 As Double = 0.30 'font size in cm
Dim sFSize3 As Double = 0.25 'font size in cm
Dim sFSize4 As Double = 0.10 'font size in cm

'Part Number
Dim sString1 As String = GetFormatedProperty(sFont, sFSize2, False, "Part Number", 5)
'Scale
Dim sString2 As String = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "'> (SCALE: </StyleOverride>"
Dim sString3 = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "'><DrawingViewScale/>)</StyleOverride>"
'Type 
Dim sString4 As String = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize3 & "'>TYPE: </StyleOverride>"
Dim sString5 As String = GetFormatedProperty(sFont, sFSize2, True, "TEKST PLAAT")
'Dikte
Dim sString6 As String = GetFormatedProperty(sFont, sFSize2, True, "DIKTE")
Dim sString7 As String = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize3 & "' Bold='True'> mm </StyleOverride>"
'Materiaal
Dim sString8 As String = GetFormatedProperty(sFont, sFSize2, True, "MATERIAL")
'Aantal
Dim sString9 As String = "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize3 & "' >AANTAL: </StyleOverride>"
Dim sString10 As String = GetFormatedProperty(sFont, sFSize2, True, "PartQty")


Dim oDoc As DrawingDocument = ThisDoc.Document

Dim oSSet As SelectSet = oDoc.SelectSet
If oSSet.count = 0 Then
    MessageBox.Show("View(s) selecteren", "Let op")
    Exit Sub
End If

For Each Item As Object In oSSet
    If Not TypeOf(Item) Is DrawingView Then Continue For
    Dim oView As DrawingView = CType(Item, DrawingView)
    oView.ShowLabel = True 'Make view label visible
    
    'Add lines to the view label, break lines using:  "<Br/>" 
    oView.Label.FormattedText = sString1 & "<Br/>" & _
    sString2 & sString3 & "<Br/>" & _
    sString4 & sString5 & sString6 & sString7 & sString8 & sString9 & sString10
Next
End Sub

Private Function GetFormatedProperty(oFont As String, oFontSize As Double, UserProperty As Boolean, PropertyName As String, Optional PropertyID As Integer = 0) As String
    Dim PropertyType As String = "Design Tracking Properties"
    Dim ProID As String = vbNullString
    If UserProperty Then PropertyType = "User Defined Properties" Else ProID = "PropertyID='" & PropertyID & "'"
    Return "<StyleOverride Font='" & oFont & "' FontSize='" & oFontSize & "' Bold='True'>" & _
    "<Property Document='model' PropertySet='" & PropertyType & "' Property='" & PropertyName & "' " & _
    "FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' " & ProID & ">" & PropertyName & "</Property> </StyleOverride>"
End Function

 

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 10
Anonymous
in reply to: Owner2229

Hi Mike,

 

hmm I tried the new code you posted, but unfortunately without succes... I still get an error.

 

Please look at the following screen capture to see the exact event (I hope this forum allows me to place an external link)

 

http://recordit.co/Mv3fRJObK4

 

Many thanks,

Jesse 

Message 4 of 10
Owner2229
in reply to: Anonymous

Hmm, that's strange. As I can't reproduce the issue, can you please try this?

Place this code right under this "Dim oView As DrawingView"

 

Dim oModel As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
oModel.Update()
Dim IsDirty As String = oModel.Dirty.ToString
MsgBox(IsDirty & vbNewLine & sString1 & "<Br/>" & sString2 & sString3 & "<Br/>" & _ sString4 & sString5 & sString6 & sString7 & sString8 & sString9 & sString10)

 

And run the rule twice again (with and without error) and post screenshots of both showed messages.

We have to dig up what changed that's causing the error.

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 10
Anonymous
in reply to: Owner2229

Hi Mike,

 

Please see the attached images. Image '4' is from the part without the error and image '5' is from the part with the error

Message 6 of 10
Owner2229
in reply to: Anonymous

I've just edited it, can you try it again, please? Also, there's no difference at all...

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 7 of 10
Anonymous
in reply to: Owner2229

Alright,

 

6 is the good one

7 is the one with the error

 

Thanks!

Message 8 of 10
Owner2229
in reply to: Anonymous

Alright, one more round. Again under the oView.

 

Dim oModel As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oPropsets As PropertySets = oModel.PropertySets
Dim oPropSetA As PropertySet = oPropsets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}") 'Project
Dim oPropSetB As PropertySet = oPropsets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}") 'User
Dim iA As String = oPropSetA.Item("Part Number").Expression
Dim iB As String = oPropSetB.Item("TEKST PLAAT").Expression
Dim iC As String = oPropSetB.Item("DIKTE").Expression
Dim iD As String = oPropSetB.Item("MATERIAL").Expression
Dim iE As String = oPropSetB.Item("PartQty").Expression
MsgBox(iA & vbnewline & iB & vbnewline & iC & vbnewline & iD & vbnewline & iE)

 

 

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 9 of 10
Anonymous
in reply to: Owner2229

image 8 is the good one

image 9 is the one with the error (although i didn't get the error this time)

Message 10 of 10
Owner2229
in reply to: Anonymous

Alright then, maybe there's some iProperties narrowing going on, try it without the MsgBox(), but keep the iProperties declarations.

 

Let's see if it still works. It's a nasty workaround, but if it works ¯\_(ツ)_/¯

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

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

Post to forums  

Autodesk Design & Make Report