iLOGIC Insert Sketched Symbols

iLOGIC Insert Sketched Symbols

Anonymous
Not applicable
4,004 Views
24 Replies
Message 1 of 25

iLOGIC Insert Sketched Symbols

Anonymous
Not applicable
I'm wondering if there is a way to automatically insert sketch symbols into views using iLOGIC? I would like to create 2 criteria. I would like to insert a symbol on the "ORIGIN" of each view on the page. I would like to insert a symbol on the "COG" of each view on the page. My desired symbol is located here: "Drawing Resources, Sketched Symbols, Stamps & Symbols, COG / Datum" Thanks
0 Likes
4,005 Views
24 Replies
Replies (24)
Message 2 of 25

MechMachineMan
Advisor
Advisor

Not through iLogic per se, but within the rule environment you can code using some partial vb.net statements, which allow you access to the various objects available in the inventor API.

On your computer there is a file in one of the inventor folders named something like "admapi_21_0.chm" (depending on what version of inventor you use). This will give you an idea of what you can access.

Sketched symbols is one of these, and you can likely accomplish what you ask... just fetching the coordinates to place the symbol from the model and converting it to the drawing space location will be the tough part. Additionally, if your symbols you want to add contain prompted entries, that also adds to the complexity of code required to add the symbols.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 25

machiel.veldkamp
Collaborator
Collaborator

SyntaxEditor Code Snippet

Sub Main()
     Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    Dim oDrawingStatus As New ArrayList
    
    'Choose the drawing state
    oDrawingStatus.Add("PRELIMENARY")
    oDrawingStatus.Add("FOR APPROVAL")
    oDrawingStatus.Add("APPROVED FOR CONSTRUCTION")
    
    iProperties.Value("Status", "Status") = InputListBox("Select the drawing state", oDrawingStatus, oDrawingStatus , Title := "Status", ListName := "Drawing Status")
    checkDouble
    iLogicVb.UpdateWhenDone = True

End Sub


Sub checkDouble()
    'checks whether the sheet already has symbols and if (EU) Drawing State needs updating or needs placement.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    Dim oSketchedSymbolDef As SketchedSymbolDefinition
    oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item("(EU) DRAWING STATE")
    Dim s As Sheet 
    Dim i As Integer
    
    For Each s In oDrawDoc.Sheets 'checks each sheet
        s.Activate    'Activate Sheet
        Dim sym As SketchedSymbol 
        For Each sym In s.SketchedSymbols 'Run through the symbols
            If sym.Definition Is oSketchedSymbolDef Then 'if (EU) then
                iLogicVb.UpdateWhenDone = True    'update Symbol
            End If
            
            For Each symb In s.SketchedSymbols    'loop in loop to see if EU is present
                If symb.Definition Is oSketchedSymbolDef Then
                    i=i+1
                End If
            Next
            
            If sym.Definition IsNot oSketchedSymbolDef AndAlso (i<2)Then 
                InsertSketchedSymbolOnSheet    
            End If
        Next
        
        If (oDrawDoc.ActiveSheet.SketchedSymbols.Count < 1) Then
            InsertSketchedSymbolOnSheet    
        End If
    Next 
End Sub

Public Sub InsertSketchedSymbolOnSheet()
    'MessageBox.Show("Komt ie dan?()", "Title")
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    
    Dim yCo As Integer
    yCo = ActiveSheet.Height
    Dim xCo As Integer
    xCo = ActiveSheet.Width

    ' Obtain a reference to the desired sketched symbol definition.
    Dim oSketchedSymbolDef As SketchedSymbolDefinition
    oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item("(EU) DRAWING STATE")

    Dim oSheet As Sheet
    oSheet = oDrawDoc.ActiveSheet

    Dim oTG As TransientGeometry
    oTG = ThisApplication.TransientGeometry

    Dim oSketchedSymbol As SketchedSymbol
    oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oTG.CreatePoint2d((xCo/10)-20, yCo/250), (0), 1)

End Sub

 

This is a tool that does this for us. Maybe there is some code in here you can use. Good luck 

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

___________________________
0 Likes
Message 4 of 25

Anonymous
Not applicable
I have never written any code, so I really cant follow it. I know only the very basics of iLOGIC, not VBA. I found a similar code, but it placed the symbol centered bottom of the view. Does anyone know the code for the "ORIGIN, CENTER POINT" I feel I could edit the code and copy that term into it. I tried "ORIGIN" and "CENTER POINT" but they didn't work. Below is what I would like to edit. Dim oPosition As Point2d: oPosition = oView.Center oPosition.y = oPosition.y - (oView.Height / 2 + 0.6)
0 Likes
Message 5 of 25

Curtis_Waguespack
Consultant
Consultant

Hi PhilLindsay4781,

 

Just to clarify, you are aware that Inventor can place the COG mark using built in tools, correct? :

 

https://knowledge.autodesk.com/support/inventor-products/learn-explore/caas/CloudHelp/cloudhelp/2014...

 

https://synergiscadblog.com/2013/04/15/center-of-gravity-sanity-for-inventor-assemblies/

 

 

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

EESignature

0 Likes
Message 6 of 25

Anonymous
Not applicable
Yes, I am aware of that. However, we place a secondary symbol over that projected geometry. Can you show the COG in all views on the page using iLOGIC?
0 Likes
Message 7 of 25

Curtis_Waguespack
Consultant
Consultant

Hi PhilLindsay4781,

 

I found this, which has an example of showing the COG in a drawing view:

http://forums.autodesk.com/t5/inventor-forum/hide-center-of-gravity-in-idw-drawing-view/td-p/4943408

 

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

EESignature

0 Likes
Message 8 of 25

Anonymous
Not applicable
The code doesn't work. "LET" and "SET" are no longer supported ERROR occurs. What is the new "LET" command?
0 Likes
Message 9 of 25

MechMachineMan
Advisor
Advisor
Let and Set are from VBA. If you are doing iLogic/vb.net, just delete those
words wherever they appear.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 10 of 25

Curtis_Waguespack
Consultant
Consultant

Hi PhilLindsay4781,

 

You'll probably need to stop and learn a bit more about authoring your own code, to be able to go much further on your own, but here is a working Ilogic example based off of the example at the previous link.

 

This example places a center mark at the COG in each view.

 

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

'Define the drawing sheet
Dim oSheet As Sheet
oSheet =  oDoc.ActiveSheet

For Each oView In oSheet.DrawingViews
	Dim oAddCofG As Object
	oAddCoG = oSheet.Centermarks.AddByCenterOfGravity(oView)
Next 'next view

 

So now your goal, as I understand it is to place a sketched symbol at the co-ordinates of each COG point. I'll try to post back a working example in a bit.

 

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

EESignature

Message 11 of 25

Anonymous
Not applicable
The above code worked!!! Now im trying to attach a sketched symbol to that mark that is generated
0 Likes
Message 12 of 25

Curtis_Waguespack
Consultant
Consultant

Hi PhilLindsay4781,

 

Have a look at this example. This places a symbol on the Center of Gravity center point.

 

This example also runs through the existing symbols, looking for the named symbol, and deletes existing instances if found. This prevents symbols on top of symbols if the code is run again, say if a new view is created. I couldn't get this example to update consistently, without adding a line that deletes the COG center point after the symbol is placed.

 

Here's the gotcha' to using this. The symbol is not going to update if the COG changes, so this rule will need to be run again. Note that I tested to see if deleting the sketch point made any difference to the keeping this updated, and it made no difference as far as I could tell.

 

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

 

'change the symbol name
'here as needed
Dim oSymbolName As String
oSymbolName = "MySymbol"

'defind the document
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

'get the symbol definition to use
Dim oSketchedSymbolDef As SketchedSymbolDefinition
oSketchedSymbolDef = oDoc.SketchedSymbolDefinitions.Item(oSymbolName)

'Define the drawing sheet
Dim oSheet As Sheet
oSheet =  oDoc.ActiveSheet

'[ clean up existing symbols
'look at each symbol on the sheet 
'and delete existing symbols if found
For Each oSymbol In oSheet.SketchedSymbols
	'look for symbol by name
	If oSymbol.Name = oSymbolName Then
		oSymbol.Delete
	End If
Next 'symbol
']


'[ place new symbols
For Each oView In oSheet.DrawingViews
	'find Center of Gravity
	'and place center mark
	
	Dim oCofG As Object
	oCoG = oSheet.Centermarks.AddByCenterOfGravity(oView)

	'get center mark co-ordinates
	Dim oPoint As Point2d
	oPoint = oCoG.Position
	
	'place symbol
	Dim oSketchedSymbol As SketchedSymbol
    oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oPoint,0, 1)
	
	'delete center mark
	oCoG.Delete
	
Next 'next view
']

 

EESignature

0 Likes
Message 13 of 25

Anonymous
Not applicable
Is there a repository of these designations you are using? The last code worked perfectly. Are these commands just all memorized? I follow the last one vaguely ... I think for my next objective I need to edit the following line "Dim oCofG As Object oCofG = oSheet.Centermarks.AddByCenterOfGravity(oView)" I need this to reference the "ORIGIN" or the "CENTER POINT". I cannot find anything that lists the language promps needed for this criteria.
0 Likes
Message 14 of 25

Anonymous
Not applicable
0 Likes
Message 15 of 25

Curtis_Waguespack
Consultant
Consultant

Hi PhilLindsay4781,

 

That link is for AutoCAD.

 

Have a look here:

http://usa.autodesk.com/adsk/servlet/index?id=1079044&siteID=123112

 

 

You can find examples in the API help files:

pic_1

 

And the object model map for Inventor is listed at that link, see text just above this image on that page:

object-model-chart-1-large-617x399

 

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

EESignature

0 Likes
Message 16 of 25

Curtis_Waguespack
Consultant
Consultant

@Anonymous wrote:
Is there a repository of these designations you are using?
Are these commands just all memorized?

Hi PhilLindsay4781,

 

A small few things I know by memory, but not much of it. If I'm trying do something unfamiliar, I look it up in the API help files, and then often I just come back here and search for that term or keyword and find a working example. Other times I search here first, and then go to the API help files in order to figure out additional syntax, etc.

 

So for example this is what I found in the API help:

 

Centermarks.AddByCenterOfGravity Method

Parent Object: Centermarks

Description

Method that creates a center mark at the center of gravity of the model in the input drawing view. This will fail in the case where the view does not contain any solid parts.

Syntax

Centermarks.AddByCenterOfGravity( DrawingView As DrawingView, [CentermarkStyle] As Variant, [Layer] As Variant ) As Centermark

Parameters

Name Description
DrawingView Specifies the view to create the center mark for.
CentermarkStyle Object that specifies the center mark style to use for the center mark. If not specified, the style defined by the active standard is used.
Layer Object that specifies the layer to use for the center mark. If not specified, the layer defined by the active standard is used.

Version

Introduced in Inventor version 2010


© Copyright 2014 Autodesk, Inc.

 

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

EESignature

0 Likes
Message 17 of 25

Curtis_Waguespack
Consultant
Consultant

@Anonymous wrote:
I need this to reference the "ORIGIN" or the "CENTER POINT".

Hi PhilLindsay4781,

 

I still don't understand what ORIGIN or CENTER POINT means in terms of a drawing view. Do you mean the 0,0,0 point of the assembly file that the drawing view references?

 

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

EESignature

0 Likes
Message 18 of 25

Anonymous
Not applicable
Yes the 0,0,0 coordinate of the model in the specific view.
0 Likes
Message 19 of 25

Curtis_Waguespack
Consultant
Consultant

Hi PhilLindsay4781,

 

Have a look at this example. I got interrupted in the middle, so hopefully I didn't miss something.

 

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

 

 

 

'change the symbol name
'here as needed
Dim oSymbolName As String
oSymbolName = "MySymbol"

'define the document
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

'get the symbol definition to use
Dim oSketchedSymbolDef As SketchedSymbolDefinition
oSketchedSymbolDef = oDoc.SketchedSymbolDefinitions.Item(oSymbolName)

'Define the drawing sheet
Dim oSheet As Sheet
oSheet =  oDoc.ActiveSheet

'[ clean up existing symbols
'look at each symbol on the sheet 
'and delete existing symbols if found
For Each oSymbol In oSheet.SketchedSymbols
	'look for symbol by name
	If oSymbol.Name = oSymbolName Then
		oSymbol.Delete
	End If
Next 'symbol
']


'[ place new symbols
For Each oView In oSheet.DrawingViews
	
	'get the model from the view
	Dim oModel as Document
	oModel = ActiveSheet.View(oView.Name).ModelDocument
	
	'get the origin workpoint
	oOriginPoint = oModel.ComponentDefinition.WorkPoints(1)
	
	'place center mark
	Dim oCenterMark As Object
	oCenterMark = oSheet.Centermarks.AddByWorkFeature(oOriginPoint,oView)

	'get center mark co-ordinates
	Dim oPoint As Point2d
	oPoint = oCenterMark.Position
		
	'place symbol
	Dim oSketchedSymbol As SketchedSymbol
    oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oPoint,0, 1)
	
	'delete center mark
	oCenterMark.Delete
	
Next 'next view
']

 

EESignature

Message 20 of 25

Anonymous
Not applicable
FANTASTIC!!! It works! You guys are a great help!