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 Sketch Symbol using ilogic

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
Anonymous
10136 Views, 16 Replies

Insert Sketch Symbol using ilogic

Hey All Please Help......

 

I want Inventor to add sketch symbols automaticly on cordinates according to a Custom Text Paramater

for example I have created Custom Multi Value Text User parameter Approved & Not Approved or Plate Work Notes & SteelWork Notes  wich each represent diffrent sketch symbols that needs to be placed out base on the value selected. Each sheet consist of diffrent sketch symbols

 

Any Help will be much Appreciated or example Ilogic Rule

 

Thanks

Carl

16 REPLIES 16
Message 2 of 17
Vladimir.Ananyev
in reply to: Anonymous

Your problem can be solved.

Inventor DrawingDocument API allows you (a) create new sketched symbol definition object  on-the-fly and (b) insert existing sketched symbol definition into the drawing sheet. 

The following rule inserts the sketched symbol definition "SymbolA" into the active sheet, insertion point (10 cm, 10 cm).

'Sub Main() 
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument = ThisDrawing.Document
 
' Obtain a reference to the desired sketched symbol definition.
Dim oSketchedSymbolDef As SketchedSymbolDefinition _
       = oDrawDoc.SketchedSymbolDefinitions.Item("SymbolA")
 
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
 
'create insertion point, coordinates - in cm !
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(10, 10)
 
' Add an instance of the sketched symbol definition to the sheet.
' Rotate angle = 0 radians,
' scale = 1 when adding
' no prompt text
Dim oSketchedSymbol As SketchedSymbol _
       = oSheet.SketchedSymbols.Add( _
             oSketchedSymbolDef, _
             oInsertionPoint, _
             0, 1, Nothing)
'End Sub

Look Inventor API Help for the sample code “Create SketchedSymbol Definition API Sample“  for more details.

Cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 17

I paste this Exact code into a iLogic rule, with a SymboA defined in my Sketched symbols, and I ge tthis error

 

Error in rule: Rule0, in document: Drawing1

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

I'm using Inventor 2014, I have also tried it in Inventor 2015

 

thoughts?

 

 

 

Message 4 of 17
GosponZ
in reply to: kimhendrix

When i tried for first time i got same error. I changed Symbol1A into one  of my sketched symbols and is working. Inventor 2012. Would be nice run this rule and with pick geometry to start symbol with leader.

Would be this possible, Vladimir?

Thank you

Message 5 of 17
kimhendrix
in reply to: GosponZ

I have changed that I still get the same message

 

Message 6 of 17
GosponZ
in reply to: kimhendrix

Did you copy and paste code in text editor first?Word maybe? I do all the time

Message 7 of 17
kimhendrix
in reply to: GosponZ

'Sub Main() 
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument = ThisDrawing.Document
 
' Obtain a reference to the desired sketched symbol definition.
Dim oSketchedSymbolDef As SketchedSymbolDefinition _
       = oDrawDoc.SketchedSymbolDefinitions.Item("SymbolA")
 
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
 
'create insertion point, coordinates - in cm !
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(10, 10)
 
' Add an instance of the sketched symbol definition to the sheet.
' Rotate angle = 0 radians,
' scale = 1 when adding
' no prompt text
Dim oSketchedSymbol As SketchedSymbol _
       = oSheet.SketchedSymbols.Add( _
             oSketchedSymbolDef, _
             oInsertionPoint, _
             0, 1, Nothing)
'End Sub

 This is a COPY paste from my ilogic rule

screen shot

Message 8 of 17
kimhendrix
in reply to: kimhendrix

I copied to Word, and tried Notepad still exact error 

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.SketchedSymbols.Add(Object SketchedSymbolDefinition, Point2d Position, Double Rotation, Double Scale, Object PromptStrings)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

Message 9 of 17

Hi kimhendrix,

 

In your original message you say "paste this Exact code into a iLogic rule, with a SymboA.."

 

That might just be a typo, but I wanted to point out that the rule is looking for a symbol named SymbolA rather than SymboA.

 

I did test the rule, where I didn't have a symbol named SymbolA, and it appeared to throw the same error you're seeing.

 

Aside from that the other thing that you might try is to change the first line from:

 

Dim oDrawDoc As DrawingDocument = ThisDrawing.Document 

to:

 

Dim oDrawDoc As DrawingDocument = ThisDoc.Document 

 

Otherwise, the rule works fine for me.

 

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

 

 

Message 10 of 17
GosponZ
in reply to: Curtis_Waguespack

If you have prompted entry in symbol rule won't work.

Curtis, how about to pick line in drawing after run rule and pull leader wit symbol, is that possible?

Thank you

Message 11 of 17
Miguel.CarvajalS34Q6
in reply to: Anonymous

I have the need to insert a block or symbol in the drawing sheet, but the position in which it is inserted changes with respect to the format that is used at the moment, the insertion position can be adjusted programmatically if it is A4 or A3 etc.

Message 12 of 17
leoow96
in reply to: GosponZ

It is really the symbol itself. If an input is required by the symbol, then the rule does not work. If it is an icon without a request for input, then the rule works.


Does anyone perhaps already have a solution for an icon with a request for input?


Greetings


Leo

Message 13 of 17
Ethibaudeau
in reply to: leoow96

For sketch symbols with prompted entries, the argument "PromptStrings" of "SketchedSymbols.Add" requires a array of strings, even if it is a single entry:

 

Dim promptText(0) As String
promptText(0) = "99"

 

 

I found that the above did not work with a simple string, but worked once it was an array with a single string. Found this the hard way, then I read the documentation closer and sure enough it states "Optional input array of Strings"

Message 14 of 17
leoow96
in reply to: Ethibaudeau

Thanks for your answer.


It doesn't quite work for me yet. How do I include the code from you?


My code looks like this:

 

 

 

Parameter.UpdateAfterChange = True
'Sub Main() 
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument = ThisDoc.Document 
 
' Obtain a reference to the desired sketched symbol definition.
Dim oSketchedSymbolDef As SketchedSymbolDefinition _
       = oDrawDoc.SketchedSymbolDefinitions.Item("Oberflächen, Sammelangabe w, x, y (3 Qualitäten, nicht vordefiniert)")
 
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
 
'create insertion point, coordinates - in cm !
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(10, 10)

Dim promptText(0) As String
promptText(0) = "99"

Dim oSketchedSymbol As SketchedSymbol _
       = oSheet.SketchedSymbols.Add( _
             oSketchedSymbolDef, _
             oInsertionPoint, _
             0, 1, Nothing)
'End Sub

 

 

I get the following error:

Error in line 24 in rule Surfaces, collective specification w, x, y (3 qualities, not predefined), in document Drawing (DWV).idw

Wrong parameter. (Exception of HRESULT: 0x80070057 (E_INVALIDARG))

 

 

My goal is to easily call the following dialog from Inventor from my sketch icon via a rule:

Unbenannt.PNG

Message 15 of 17
Ethibaudeau
in reply to: leoow96

@leoow96 

Have a look at the documentation for the .Add method of the SketchedSymbols object:
https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=SketchedSymbols_Add

 

The 5th argument of SketchedSymbols.Add() is "PromptStrings" as Variant.


Your code has the 5th argument as "Nothing". You need to change that to be the array of strings "PromptText".

Message 16 of 17
leoow96
in reply to: Ethibaudeau

Now it works so far, with an empty string! Now my symbol is placed.


How do I get it now that the window opens to edit the properties?

 

 

 

Unbenannt.PNG

 

I would be reluctant to make a query that asks for the value.

Message 17 of 17
Ethibaudeau
in reply to: leoow96

Having the GUI window open up kind of defeats the purpose of using the code to generate the SketchedSymbol. You probably want the code to create these entries, right?

 

I'm not sure why the string in your Sketched Symbol is empty, but I see from the image you posted that your SketchedSymbol contains two entries. You probably need a string array of length 2, with each filled out:

 

 

Dim promptText(1) As String  'String Array of length 2
promptText(0) = "First Entry"
promptText(1) = "Second Entry"

 

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

Post to forums  

Autodesk Design & Make Report