Inventor Customization

Reply
Valued Mentor
SeanFarr
Posts: 475
Registered: ‎07-25-2012
Message 1 of 7 (624 Views)
Accepted Solution

iLogic Rules in .idw result in errors.. sometimes

624 Views, 6 Replies
11-29-2012 09:31 AM

Good Day,

 

I have 3 iLogic Rules that I use with my idw's,

 

1-SCALE -  is to update scale in the title block

2- WEIGHT - is to update weight of model in title block

3- PDF - is to create a pdf version of drawing in same location as idw

 

all are triggered by saving the drawing.

 

These work fine, but sometimes when I create specific types of drawings there is errors, which is no big deal, just a prompt appears and I press ok and everything is fine.

 

With very little to no iLogic programming knowledge, is there a way to edit to rules so that if there is an issue, the rule knows it is ok and saves without the little prompt appearing?

 

Example of when errors occur for:

 

SCALE - sometimes I create drawings on my template just using create sketch, I don't place a base view so therefore there is no model information. which makes it hard to produce a scale. (see image, error -1)

 

WEIGHT - occurs during the same instance as above, only a sketch is saved on the idw. (see image error -2)

but I also have an error occur when creating a drawing from a presentation file. I create a presentation file from a specific level of detail from an assembly. and I get an error when saving . (see image error-3)

 

I understand the first 2 errors because there is no physical data to get this information from, so I am hoping an edit to the rules can bypass this issue. But the 3rd error doesn't make sense. It is from an actual model, but I guess the physical properties get lost from an .iam to .ipn?? or is there a setting that can be toggled to carry over model properties?

 

 

Thanks for any help!

 

Sean

 

Inventor Pro 2013

 

 

 

Rules are below:

 

'Scale

Public Sub Main()
  On Error Resume Next
  'Get the drawing document
  Dim oDrawingDoc As Inventor.DrawingDocument
  oDrawingDoc = ThisApplication.ActiveDocument
  'Dim oErrResponse As VbMsgBoxResult
  If Err.number <> 0 Then
    MsgBox("Active document must be a drawing", vbExclamation, "Error")
    Exit Sub
  End If
 
  'Get the first sheet
  Dim oSheet As Inventor.Sheet
  oSheet = oDrawingDoc.Sheets.Item(1)
 
  'Get the first view
  Dim oView As Inventor.DrawingView
  oView = oSheet.DrawingViews.Item(1)
  If Err.number <> 0 Then
    MsgBox("Drawing has no views", vbExclamation, "Error")
    Exit Sub
  End If
 
  'Get the view scale string
  Dim sViewScale As String
  sViewScale = oView.ScaleString
 
  'Get the custom propertyset
 Dim oCustomPropSet As Inventor.PropertySet
 oCustomPropSet = oDrawingDoc.PropertySets.Item("Inventor User Defined Properties")
 
  'Get the "Scale" custom iproperty.  If it doesn't exist, we'll create it
  Dim oScaleProp As Inventor.Property
  oScaleProp = oCustomPropSet.Item("Scale")
  If Err.number <> 0 Then
  oScaleProp = oCustomPropSet.Add("", "Scale")
  End If
  oScaleProp.Value = sViewScale
 
  'Update the drawing.  This will update the title block scale
  oDrawingDoc.Update
End Sub





'Weight

doc = ThisDoc.Document
customPropertySet = doc.PropertySets.Item("Inventor User Defined Properties")
 
'Make sure TotalWT property exists
Try
      prop = customPropertySet.Item("TotalWT")
Catch
      'Assume error means not found
      customPropertySet.Add("", "TotalWT")
End Try


'Find the filename of the model used in the drawing
modeldocname = IO.Path.GetFileName(ThisDoc.ModelDocument.FullFileName)

'Find the mass of the model used in the drawing
mass = iProperties.Mass(modeldocname)


'Write the mass of the model to the TotalWT custom iProperty.
'The mass is converted from kg to lbs and rounded to the nearest integer
iProperties.Value("Custom", "TotalWT") = (Round((mass*2.20462262)*2))/2


InventorVb.DocumentUpdate()







'PDF Creating

'Save PDF with options
path_and_namePDF = ThisDoc.PathAndFileName(False) ' without extension
PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

If PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
'oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("Custom_End_Sheet") = 4
End If

'Set the destination file name
oDataMedium.FileName = path_and_namePDF & ".pdf"

On Error Goto handlePDFLock
'Publish document.
Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

Exit Sub

handlePDFLock:
MessageBox.Show("PDF could not be saved, most likely someone else has it open.", _
"No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
Resume Next

Sean Farr
Product Designer at TESInc.ca

Inventor Professional 2014-Update 2 - AutoCAD Electrical 2014
Win7-x64 | ASUS P8Z77-V | i7 3770 -3.4 GHz | 32GB RAM |
240GB SSD | nVidia GTX 670 4GB - 320.49
*Expert Elite*
Curtis_Waguespack
Posts: 2,780
Registered: ‎03-08-2006
Message 2 of 7 (617 Views)

Re: iLogic Rules in .idw result in errors.. sometimes

11-29-2012 10:05 AM in reply to: SeanFarr

 

Hi SeanFarr,

 

Here's a quick solution for the first to issues (the changes have been made in blue). I think this will handle the 3rd issues also, but I did not test it.

 

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

 

'Scale

Public Sub Main()
  On Error Resume Next
  'Get the drawing document
  Dim oDrawingDoc As Inventor.DrawingDocument
  oDrawingDoc = ThisApplication.ActiveDocument
  'Dim oErrResponse As VbMsgBoxResult
  If Err.number <> 0 Then
    MsgBox("Active document must be a drawing", vbExclamation, "Error")
    Exit Sub
  End If
 
  'Get the first sheet
  Dim oSheet As Inventor.Sheet
  oSheet = oDrawingDoc.Sheets.Item(1)
 
  'Get the first view
  Dim oView As Inventor.DrawingView
  oView = oSheet.DrawingViews.Item(1)
  If Err.number <> 0 Then
    Resume Next
    Exit Sub
  End If
 
  'Get the view scale string
  Dim sViewScale As String
  sViewScale = oView.ScaleString
 
  'Get the custom propertyset
 Dim oCustomPropSet As Inventor.PropertySet
 oCustomPropSet = oDrawingDoc.PropertySets.Item("Inventor User Defined Properties")
 
  'Get the "Scale" custom iproperty.  If it doesn't exist, we'll create it
  Dim oScaleProp As Inventor.Property
  oScaleProp = oCustomPropSet.Item("Scale")
  If Err.number <> 0 Then
  oScaleProp = oCustomPropSet.Add("", "Scale")
  End If
  oScaleProp.Value = sViewScale
 
  'Update the drawing.  This will update the title block scale
  oDrawingDoc.Update
End Sub

 

'Weight

doc = ThisDoc.Document
customPropertySet = doc.PropertySets.Item("Inventor User Defined Properties")
 
'Make sure TotalWT property exists
Try
      prop = customPropertySet.Item("TotalWT")
Catch
      'Assume error means not found
      customPropertySet.Add("", "TotalWT")
End Try

'Find the filename of the model used in the drawing
If ThisDoc.ModelDocument Is Nothing Then
Goto handleNoModel
Else
modeldocname = IO.Path.GetFileName(ThisDoc.ModelDocument.FullFileName) 
End If

'Find the mass of the model used in the drawing
mass = iProperties.Mass(modeldocname)

'Write the mass of the model to the TotalWT custom iProperty.
'The mass is converted from kg to lbs and rounded to the nearest integer
iProperties.Value("Custom", "TotalWT") = (Round((mass*2.20462262)*2))/2

InventorVb.DocumentUpdate()

Exit Sub
handleNoModel:
'do nothing 

 



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





Valued Mentor
SeanFarr
Posts: 475
Registered: ‎07-25-2012
Message 3 of 7 (613 Views)

Re: iLogic Rules in .idw result in errors.. sometimes

11-29-2012 10:59 AM in reply to: Curtis_Waguespack

Thanks Curtis,

 

Those edits definitely helped with having a sketch only as a drawing, but for some reason, when I select a base view of an .ipn file I still get a error. (see image)

 

The rule works with all .ipt and .iam files.

 

The weight is not a huge issue for an exploded view drawing, I can always create a drawing of the same components, but just leave it as an .iam file.

 

This post was mainly to bypass the error prompt.

 

Thanks for your help this far...

 

Sean

Sean Farr
Product Designer at TESInc.ca

Inventor Professional 2014-Update 2 - AutoCAD Electrical 2014
Win7-x64 | ASUS P8Z77-V | i7 3770 -3.4 GHz | 32GB RAM |
240GB SSD | nVidia GTX 670 4GB - 320.49
*Expert Elite*
Curtis_Waguespack
Posts: 2,780
Registered: ‎03-08-2006
Message 4 of 7 (608 Views)

Re: iLogic Rules in .idw result in errors.. sometimes

11-29-2012 12:41 PM in reply to: SeanFarr

Hi SeanFarr,

 

If you replace this:

 

 

'Find the mass of the model used in the drawing
mass = iProperties.Mass(modeldocname)

 with this:

 

'Find the mass of the model used in the drawing
If iProperties.Mass(modeldocname) = "" Then
'do nothing
Else
mass = iProperties.Mass(modeldocname)
End If

 

I think (I didn't test it)  you'll step past the issue. But if you need the IPN to be updated with the weight when none is found, I think that could be done as well.

 

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

 



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





Valued Mentor
SeanFarr
Posts: 475
Registered: ‎07-25-2012
Message 5 of 7 (584 Views)

Re: iLogic Rules in .idw result in errors.. sometimes

11-30-2012 08:26 AM in reply to: Curtis_Waguespack

Hmm. still get the same error prompt pop up.

 

Maybe it is easier to not bypass the weight error issue and write the rule to put in the actual model weight??

 

I have no idea...haha...

 

 

I don't use a lot of .ipn files so it is not a daily nuisance.

 

Thanks for your help anyways Curtis!

 

Sean

Sean Farr
Product Designer at TESInc.ca

Inventor Professional 2014-Update 2 - AutoCAD Electrical 2014
Win7-x64 | ASUS P8Z77-V | i7 3770 -3.4 GHz | 32GB RAM |
240GB SSD | nVidia GTX 670 4GB - 320.49
*Expert Elite*
Curtis_Waguespack
Posts: 2,780
Registered: ‎03-08-2006
Message 6 of 7 (582 Views)

Re: iLogic Rules in .idw result in errors.. sometimes

11-30-2012 09:23 AM in reply to: SeanFarr

Hi SeanFarr,

 

That's what I get for guessing! :smileytongue:

 

I tested this version, and it seems to handle the IPN error well.

 

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

 

 

'Weight

doc = ThisDoc.Document
customPropertySet = doc.PropertySets.Item("Inventor User Defined Properties")
 
'Make sure TotalWT property exists
Try
      prop = customPropertySet.Item("TotalWT")
Catch
      'Assume error means not found
      customPropertySet.Add("", "TotalWT")
End Try

'Find the filename of the model used in the drawing
If ThisDoc.ModelDocument Is Nothing Then
Goto handleErrors
Elseif ThisDoc.ModelDocument.DocumentType = kPresentationDocumentObject
Goto handleErrors
Else
modeldocname = IO.Path.GetFileName(ThisDoc.ModelDocument.FullFileName) 
End If

'Find the mass of the model used in the drawing
mass = iProperties.Mass(modeldocname)


'Write the mass of the model to the TotalWT custom iProperty.
'The mass is converted from kg to lbs and rounded to the nearest integer
iProperties.Value("Custom", "TotalWT") = (Round((mass*2.20462262)*2))/2

InventorVb.DocumentUpdate()

Exit Sub
handleErrors:
'do nothing 

 



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





Valued Mentor
SeanFarr
Posts: 475
Registered: ‎07-25-2012
Message 7 of 7 (574 Views)

Re: iLogic Rules in .idw result in errors.. sometimes

11-30-2012 11:21 AM in reply to: Curtis_Waguespack

Thanks for your time Curtis!

 

That worked perfectly, no more little error prompts!

 

Have a good weekend!

 

Sean

Sean Farr
Product Designer at TESInc.ca

Inventor Professional 2014-Update 2 - AutoCAD Electrical 2014
Win7-x64 | ASUS P8Z77-V | i7 3770 -3.4 GHz | 32GB RAM |
240GB SSD | nVidia GTX 670 4GB - 320.49

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube