I am slowly getting into drawing automation with iLogic and I've already learned a lot just watching the video on http://www.symetri.co.uk/blog/details/automating-dimensions-with-ilogic
I copied their iLogic code to try it for myself and creating a linear dimension between two faces works great.
I also got the code to work if I want to place a diameter on a round object
What I am now struggling with, is to create a linear dimension between two work points that are set to "include" in the idw. I think it has something do with with the way I am defining the work points. For the faces, the code snippet that defines the edges looks like this:
'finds edges with a particular attributes then taks the first instance Dim aoEdge3 as face oObjs = oAssyDoc.AttributeManager.FindObjects("DIM", "RHS", "1") aoEdge3 = oObjs.Item(1) 'Finds the drawing edge that represents the one with the attribute Dim aoDrawCurves4 As DrawingCurve oDrawViewCurves = oView.DrawingCurves(aoEdge4) aoDrawCurves4 = oDrawViewCurves.Item(1)
What I don't know, is how to define the work points. I tried to define the aoDrawCurves4 As Point2d but that didn't work.
Any help is appreciated.
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hey there. No worries, keep asking if you're stuck. I've had tons of help when I first got into it, just paying it forward. In a few months you'll be answering questions from people getting into drawing automation 🙂
As for the text on a new line I had to google it myself as well. All these codes are pretty much standard VBA codes, stuff that also works in excel and other applications. I found this: http://www.mrexcel.com/forum/excel-questions/66757-visual-basic-applications-code-creating-multiple-...
So it looks like your code would be
oDimText.FormattedText = "<DimensionValue/>" & vbLf & "Top Plate"
So with your help and learning more about iLogic I came up with this.... It changes the dimensions to our customer layer but I want the style to be put into inches, because it is on in mm now. Please help!
Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 9661 StartFragment: 314 EndFragment: 9629 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet
ActiveSheet = ThisDrawing.Sheet("Sheet:1") 'References this document Dim oDrawDoc As DrawingDocument oDrawDoc = ThisDoc.Document 'References this drawing sheet Dim oSheet As Sheet oSheet = oDrawDoc.ActiveSheet Dim oDim as DrawingDimension Dim oDimStyle As DrawingStylesManager = oDrawDoc.StylesManager For Each oDim In oSheet.DrawingDimensions If oDim.AttributeSets.Nameisused("iLogic_Created") = True Then oDim.Layer = ThisDrawing.Document.StylesManager.Layers("Customer") End If Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager If oDimStyle = "Customer" Then oDimStyle = ThisDrawing.Document.oStylesMgr.DimensionStyles.Item("KG-in") End If Next Dim ODDoc as Inventor.Document ODDoc=ThisApplication.ActiveDocument ODDoc.AttributeManager.PurgeAttributeSets
Without testing it myself, I think the problem is that the dimensions are assigned to a layer
oDim.Layer = ThisDrawing.Document.StylesManager.Layers("Customer")
and further down you call for
If oDimStyle = "Customer" Then
But oDimStyle is dimensioned as
DrawingStylesManager = oDrawDoc.StylesManager
and not a layer.
I'm not sure if you need your dimensions to be on a layer for future code but I've never done that myself. I assign my dimensions a new style, depending on what they were created as (most of them will be created as "By Standard (your dimstyle)". I usually create two rules, one called "MetricToImperial" and another called "ImperialToMetric"and run one or the other, depending on the units the customer wants to see:
SyntaxEditor Code Snippet
'---INITIAL SETUP---'References this document Dim oDrawDoc As DrawingDocument oDrawDoc = ThisDoc.Document 'Runs these rules on all sheets, instead of just the active sheet. For Each oSheet In oDrawDoc.Sheets 'Reference the Styles Manager Dim oStylesMgr As DrawingStylesManager oStylesMgr = oDrawDoc.StylesManager 'get the reference to the target dimension style (by name) Dim oDimStyle As DimensionStyle oDimStyle = oStylesMgr.DimensionStyles.Item("OurDimStyle1") 'get the reference to the target dimension style (by name) for hole notes Dim oDimStyleHoles As DimensionStyle oDimStyleHoles = oStylesMgr.DimensionStyles.Item("OurDimStyle2") 'Reference the Dimensions Dim oDims As DrawingDimensions oDims = oSheet.DrawingDimensions 'Reference Linear Dimensions Dim oLinearDim As GeneralDimension 'Reference Ordinate Dimensions Dim oOrdDim As OrdinateDimension '---CHANGE DIMENSIONS---'change Linear dimensions (not including Angular dims) For Each oLinearDim In oDims.GeneralDimensions If TypeOf oLinearDim Is LinearGeneralDimension Then oLinearDim.Style = oDimStyle End If Next 'change Ordinate dimensions For Each oOrdDim In oDims.OrdinateDimensions oOrdDim.Style = oDimStyle Next 'change Hole and Thread Notes Dim oThreadNote As HoleThreadNote For Each oThreadNote In oSheet.DrawingNotes.HoleThreadNotes oThreadNote.Style = oDimStyleHoles Next Next 'sheet iLogicVb.UpdateWhenDone = True
So the issue is we have Shop level and customer level drawings, the shop level has dimensions on the shop layer and are in MM while the customer level dimensions are on the customer layer and need to be in IN, So I can the dimensions to go from customer to Shop layers but I can't get the dimensions to go into IN. 😞
Oh I see. Interesting concept 🙂
Ok just guessing here again but try to change the line
If oDimStyle = "Customer" Then
to
If oDim.Layer = "Customer" Then
See if that works...
So I got it to work with the below code. Instead of applying the layer to dimensions that have the attribute "iLogic_Created" and then further down look for
If oDimStyle = "Customer" Then
I do everything at the same time. Let me know if this works or not:
SyntaxEditor Code Snippet
'---INITIAL SETUP---'On Error Resume Next 'Instead of showing errors, the code will finish all the items it can 'References this document Dim oDrawDoc As DrawingDocument oDrawDoc = ThisDoc.Document 'Runs these rules on all sheets, instead of just the active sheet. For Each oSheet In oDrawDoc.Sheets 'Reference the Styles Manager Dim oStylesMgr As DrawingStylesManager oStylesMgr = oDrawDoc.StylesManager 'get the reference to the target dimension style (by name) Dim oDimStyle1 As DimensionStyle oDimStyle1 = oStylesMgr.DimensionStyles.Item("YourDimStyle1") 'get the reference to the target dimension style (by name) for hole notes Dim oDimStyle2 As DimensionStyle oDimStyle2 = oStylesMgr.DimensionStyles.Item("YourDimStyle2") 'Reference the Dimensions Dim oDims As DrawingDimensions oDims = oSheet.DrawingDimensions 'Reference Linear Dimensions Dim oLinearDim As GeneralDimension '---CHANGE DIMENSIONS--- For Each oLinearDim In oDims.GeneralDimensions If TypeOf oLinearDim Is LinearGeneralDimension Then oLinearDim.Style = oDimStyle1 End If If oLinearDim.AttributeSets.Nameisused("iLogic_Created") Then oLinearDim.Layer = ThisDrawing.Document.StylesManager.Layers("Border (ANSI)") oLinearDim.Style = oDimStyle2 End If Next Next 'sheet iLogicVb.UpdateWhenDone = True
I actually haven't. I'm assuming you mean the visibility of the "included" work points that get turned into Centermarks?
But I just tried it and you could do something like this:
marks(3) = oSheet.Centermarks.AddByWorkFeature(WorkPoint4, oView) If oPartDoc.ComponentDefinition.Parameters.Item("YourParameter").Value = "True" Then marks(3).Visible = True Else marks(3).Visible = False End If
or if your parameter is not a true/false, just fill in the value.
I have a huge favor to ask... All of my code works perfectly thank you! My only issue is that the size of my views change obviously the scaling of them aren't controlling it well enough. So I was wondering if there is a way to say no matter what have the views set to a certain size and so all of my dimensions and view labels won't jump.
I am using this on pretty much all my drawings: http://adndevblog.typepad.com/manufacturing/2014/11/set-drawing-view-width.html
And then just put something like "Not to scale" in your title block.
Also check this out, might be helpful: http://forums.autodesk.com/t5/inventor-forum/dimension-text-position-as-dimension-changes/td-p/59797...
Oh I see, this code is still with the selecting of the view. No, I changed mine and it looks like this:
'---INITIAL SETUP---
Dim oFront As DrawingView
oFront = ActiveSheet.View("FRONT").View
'---FRONT VIEW SIZE---
' Current width
Dim oCurrentFront As Double
oCurrentFront = oFront.Width
' New width we want (set in cm)
Dim oNewFront As Double
oNewFront = 14
' New scale
Dim oScaleFront As Double
oScaleFront = oNewFront / oCurrentFront * oFront.Scale
oFront.[Scale] = oScaleFront
'---VIEW POSITIONS---
'distances are in inches, not cm (because the sheet is defined in inches)
ActiveSheet.View("FRONT").SetSpacingToCorner(5.375 , 1.75, SheetCorner.TopLeft)
The bottom part is pretty sweet. you can lock down your views on the sheet so they are always in the same spot.
So this is my issue. I am using the iLogic attribute dims as well as the view code as well.
The dimensions still "jump" I don't know why exactly.... Is it because of the scale?
Can you place the dimensions after the views have been scaled? Not sure how to fix this issue otherwise...
I usually run a "reset" rule that runs my different rules in order. First is the scaling and positioning of the views, and then add the dimensions and sort the BOM and stuff like that. Maybe that would help you as well? Just list them with
iLogicVb.RunRule(“ruleName1”)
iLogicVb.RunRule(“ruleName2”)
iLogicVb.RunRule(“ruleName3”)
First, thank you for all of your help its been great!!
Now, I have something that will be interesting to do.... 😛
I would like to have the project file to be shown after the question Ex: 123456789.ipj (or something along that line)
Also, if no was to be pressed I would like a browser to show up that would allow the user to manually map the file location.
Any ideas!?
I have the code stated below:
Sub Main iLogicVb.RunRule("CustOn")
'query user
MessageBox.Show("Would you like to print to the current Project File?: ", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
'set condition based on answer
If question = vbYes Then
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("Project", "Revision Number")
Else
End If
' Get the PDF translator Add-In.
Dim PDFAddIn As TranslatorAddIn
PDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
'Set a reference to the active document (the document to be published).
Dim oDocument As Document
oDocument = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
'Create a NameValueMap object
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
' Check whether the translator has 'SaveCopyAs' options
If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
' Options for drawings...
'oOptions.Value("Launch_Viewer") = launchviewer
oOptions.Value("All_Color_AS_Black") = 1
'oOptions.Value("Sheet_Range") = ThisApplication.PrintRangeEnum.kPrintAllSheets
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Remove_Line_Weights") = 0
'oOptions.Value("Vector_Resolution") = 400
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("Custom_End_Sheet") = 4
End If
'get PDF target folder path
oFolder = Left(ThisDoc.Path, InStrRev(oPath, "\")) & "PDF"
'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'Set the PDF target file name
Dim fname As String
fname = oFolder & "\" & oFileName & " Rev" & oRevNum & "-CUST.pdf"
oDataMedium.FileName = fname
'Publish document.
If System.IO.Directory.Exists(fname) Then
System.IO.File.Delete(fname)
MessageBox.Show("Earlier PDF deleted! ", "Inventor")
End If
PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
MessageBox.Show("Print Created in default Projects - " & fname, "Inventor")
End Sub
Hmm I've never done anything like this. Maybe you can find something on the forums. If not I'd suggest making a post in this forum.
Sorry, no help this time
If you do figure it out, I'd be interested in the solution as well as this might have a useful application for me in the future
Can't find what you're looking for? Ask the community or share your knowledge.