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: 

Insert Symbol onto Drawing View Using iLogic

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
shmartin89
2600 Views, 7 Replies

Insert Symbol onto Drawing View Using iLogic

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)

 

 

Tags (2)
7 REPLIES 7
Message 2 of 8

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:

http://forums.autodesk.com/autodesk/attachments/autodesk/120/38950/1/View%20Label%20Sketched%20Symbo...

 

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

 

Message 3 of 8

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

Message 4 of 8
shmartin89
in reply to: shmartin89

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

Message 5 of 8


@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

 

 

 

Message 6 of 8

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

 

 

Message 7 of 8

Can this be edited to link the symbol to the view ORIGIN?
Message 8 of 8

Is there any way to tweak this code to utilize: "Drawing View Orientation" as the "View Identifier" Turn on the "View / Scale Label" and hide the "Scale" Also "Underline" the text?

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

Post to forums  

Autodesk Design & Make Report