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
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
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
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
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
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
Hi SeanFarr,
That's what I get for guessing!
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
Thanks for your time Curtis!
That worked perfectly, no more little error prompts!
Have a good weekend!
Sean