Hi guys,
Im trying get a symbol to insert onto a specifc drawing view in an inventor drawing using ilogic when a rule is run.
I can get the symbol to insert with a prompt which allows the user to select the view, but I want it to insert without the user having to select the view. Is this possible by refering to the View Identifier name in the drawing view properties?
This is my code so far.
My error message is to do with refering to the view. Im not sure how to fix it.
The drawing view i want the symbol to be inserted on is called 'PART PLAN ON MAIN DECK'
Thanks
Sandy
:
Dim oApp As Application: oApp = ThisApplication
Dim oDoc As DrawingDocument: oDoc = oApp.ActiveDocument
Dim oSheet As Sheet: oSheet = oDoc.ActiveSheet
Dim oSymDef As SketchedSymbolDefinition: oSymDef = oDoc.SketchedSymbolDefinitions.Item("Container StarBoard Symbol")
Dim oView As DrawingView
oView = ActiveSheet.View("PART PLAN ON MAIN DECK")
Dim oPosition As Point2d: oPosition = oView.Center
Dim oSymbol As SketchedSymbol: oSymbol = oSheet.SketchedSymbols.Add(oSymDef, oPosition, , ,sPromptStrings)
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi shmartin89,
I don't have time right now to look closely at what you have, but here is a sample drawing that has a rule in it that might help:
The rule in this drawing adds a sketched symbol to each view on each sheet of the drawing and then sets the scale and view name to the prompted entry fields of the sketched symbol. If the symbol already exists the rule removes it and replaces it with the current scale and name in case they've changes.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Edit:
Here is a quick variation of the rule in that drawing, that will find a specific view by name, and add the symbol to that view only:
Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document
Dim oSheets As Sheets
oSheets = oDoc.Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
Dim oSymbol As SketchedSymbol
Dim oSymbols As SketchedSymbols
'iterate through all of the sheets
For Each oSheet In oSheets
'remove existing sketched symbols named View Label
For Each oSymbol In oSheet.SketchedSymbols
If oSymbol.Definition.Name = "View_Label" Then
oSymbol.Delete
Else
End if
Next
'set sheet active
oSheet.Activate
'set a refernce to the drawing views collection
oViews = oDoc.ActiveSheet.DrawingViews
' Iterate through all of the views
For Each oView In oViews
'Find a specific view by name
If oView.Name = "A" Then
'This places a sketched symbol with the name "View_Label"
Dim oSymDef As SketchedSymbolDefinition
'define the sketch symbol to be inserted
oSymDef = oDoc.SketchedSymbolDefinitions.Item("View_Label")
'set a string array with values for the
'prompted entries found in the symbol
Dim sPromptStrings(1) As String
sPromptStrings(0) = "SCALE " & oView.Scale 'set to view scale
sPromptStrings(1) = oView.Name 'set to view name
'set the position for the sketched symbol to be inserted
' and spaced off of the selected view center
Dim oPosition As Point2d: oPosition = oView.Center
oPosition.y = oPosition.y - (oView.Height / 2 + 0.6)
'insert the sketched symbol and set the prompted entries
oSymbol = oSheet.SketchedSymbols.Add _
(oSymDef, oPosition,0,1,sPromptStrings)
Else
End If
Next
Next
'activate sheet1
oDoc.Sheets.Item(1).Activate
Thanks,
This code may be of use. I want the symbol to inserted on 1 specific view though. Not every view on the sheet(s).
Im not sure how to single out a specifc view but il ahve a look.
Thanks,
Sandy
One question I have is when the symbol is inserted, how do you get it to stick to the drawing view?
Normally, I have to insert a leader & then delete it for a sketch symbol to be 'attached' to a view?
Thanks
Sandy
@shmartin89 wrote:
"...I want the symbol to inserted on 1 specific view though. Not every view on the sheet(s)."
&
"...how do you get it to stick to the drawing view?"
Hi shmartin89,
The variation code I posted in the previous response applies the symbol to a view of a specific name.
Below is another iLogic rule that applies the symbol to a specific, selected drawing view. You can run this rule in the previously linked drawing to see it in action.
As far as I can tell the symbol automatically "sticks" to the view when placed.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document
Dim oSheets As Sheets
oSheets = oDoc.Sheets
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oViews As DrawingViews
Dim oSymbol As SketchedSymbol
Dim oSymbols As SketchedSymbols
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
If oSSet.count = 0 Then
MessageBox.Show("You must select a drawing view first", "iLogic")
Exit Sub
End If
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView = trycast(oSSet.item(1), DrawingView)
'remove any existing sketched symbols named View Label
'from the selected drawing view
For Each oSymbol In oSheet.SketchedSymbols
If oSymbol.Definition.Name = "View_Label" Then
oSymbol.Delete
Else
End if
Next
If oView IsNot Nothing Then
'turn view label visibility off
oView.ShowLabel = False
'This places a sketched symbol with the name "View_Label"
Dim oSymDef As SketchedSymbolDefinition
'define the sketch symbol to be inserted
oSymDef = oDoc.SketchedSymbolDefinitions.Item("View_Label")
'set a string array with values for the prompted entries found in the symbol
Dim sPromptStrings(1) As String
sPromptStrings(0) = "SCALE " & oView.Scale 'set to view scale
sPromptStrings(1) = oView.Name 'set to view name
'set the position for the sketched symbol to be inserted
' and spaced off of the selected view center
Dim oPosition As Point2d: oPosition = oView.Center
oPosition.y = oPosition.y - (oView.Height / 2 + 0.6)
'insert the sketched symbol and set the prompted entries
oSymbol = oSheet.SketchedSymbols.Add(oSymDef, oPosition,0,1,sPromptStrings)
Else
MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
Thanks Curtis_Waguespack,
Sorry I didnt notice the post above contained this code. I have already got code which allows the user to select a view for a symbol to be entered too thanks.
It is really strange, when I run a similar rule which does the same job the symbol does not stick to the view. I ahve to insert & deleter leader but with yours it works! not sure about that one.
Cheers,
Sandy