Inventor, Ilogic, VB.NET : Insert Sketch Symbol with Rule iLogic

Inventor, Ilogic, VB.NET : Insert Sketch Symbol with Rule iLogic

Sébastien_G
Advocate Advocate
378 Views
4 Replies
Message 1 of 5

Inventor, Ilogic, VB.NET : Insert Sketch Symbol with Rule iLogic

Sébastien_G
Advocate
Advocate

Hello all,

I'm here to ask you about sketch symbols on an iLogic layout.

The question is the following:

What line of code should I write in an iLogic rule to insert a sketch symbol on a drawing?

The sketch symbol is already created.

I am sending you my dwg file which contains the sketch symbol.

Another piece of information, the code will be in an iLogic rule in an .iam assembly.

I already have the beginning of my code that creates a new drawing from a template.

I am listening to you, thank you.

@Sébastien_G 

0 Likes
379 Views
4 Replies
Replies (4)
Message 2 of 5

A.Acheson
Mentor
Mentor

The best place to find this info is the sample API files. They are written in VBA so you will need to convert them to work in the ilogic environment.

 

Look at “Public Sub InsertSketchedSymbolOnSheet()”

 

Copy the sub routine, delete the word “set”, remove the words “end Sub” and the “Public Sub heading. 

 

In the add line there is a sPrompt string which is optional you can remove this line, it will error out if you do not have prompted entry text in your symbol. Remember to change the symbol definition to the symbol name you want to insert. 

 

That should be all the changes needed. Write back if you need more information.

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 5

JelteDeJong
Mentor
Mentor

This iLogic rule will add any SketchedSymbol independent of how many prompted entries it has.

Public Sub Main()

	Dim doc As DrawingDocument = ThisDoc.Document
	Dim sheet As Sheet = doc.ActiveSheet

	Dim symbolDef As SketchedSymbolDefinition = doc.SketchedSymbolDefinitions.Item(1)

	Dim promtedEnties As List(Of String) = GetEntries(symbolDef)
	Dim point As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(12, 34)

	sheet.SketchedSymbols.Add(symbolDef, point,,, promtedEnties.ToArray())

End Sub

Public Function GetEntries(symbolDef As SketchedSymbolDefinition) As List(Of String)
	Dim values As New List(Of String)
	For Each textBox As Inventor.TextBox In symbolDef.Sketch.TextBoxes
		values.Add(String.Empty)
	Next
	Return values
End Function

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 4 of 5

Sébastien_G
Advocate
Advocate

Here is my complete code.

 

'Option à inscrire systématiquement en début de nouvelles règles
'Cette option vérifie que les variables soient déclarées
Option Explicit On
'Cette option vérifie que la valeur déclaré à un paramètre conforme à son format.
Option Strict On
Sub Main
	'[###### PARTIE A - CRÉATION DE LA PAGE DE GARDE DE LA MISE EN PLAN
	'#### DÉCLARATION DU CHEMIN D'ACCES AU GABARIT UTILISÉ POUR LA MISE EN PLAN.
	Const GabaritDwg As String = "C:\Workspace_Vault\99_Administration\01_Templates\Current Version\Site Nantes\Standard templates\Standard KTSN.dwg"

	'#### DÉCLARATION DE LA VARIABLE "ADoc" (Assembly Document) QUI EST ÉGALE À L'OBJECT ACTIF(C.A.D. L'IAM OUVERT) ET CONVERTI EN DOCUMENT ASSEMBLY.
	Dim ADoc As Inventor.AssemblyDocument = DirectCast(ThisApplication.ActiveDocument, Inventor.AssemblyDocument)

	'#### DÉCLARATION DE LA VARIABLE "NewDwg" QUI EST ÉGALE À UN OBJECT CRÉÉER À PARTIR DU GABARIT ET CONVERTI EN DOCUMENT DWG.
	'# ACTION = CRÉATION D'UN NOUVEAU PLAN DWG ###
	Dim NewDwg As Inventor.DrawingDocument = DirectCast(ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, GabaritDwg, True), Inventor.DrawingDocument)

	'#### CHOIX DU FORMAT DE LA FEUILLE.
	'# ACTION = MODIFICATION DU FORMAT DE LA FEUILLE EN A4 ###
	NewDwg.ActiveSheet.Size = DrawingSheetSizeEnum.kA4DrawingSheetSize					'A4

	'#### CHOIX DE L'ORIENTATION DE LA FEUILLE.
	'# ACTION = MODIFICATION DE L'ORIENTATION DE LA FEUILLE EN PAYSAGE ###
	NewDwg.ActiveSheet.Orientation = PageOrientationTypeEnum.kPortraitPageOrientation	'Portrait

	'#### NETTOYAGE DU TEMPLATE POUR LA PAGE DE GARDE.
	'## SUPPRESSION DES ÉLÉMENTS NON UTILISÉS (CARTOUCHE, SYMBOLES D'ESQUISSE...)
	'# ACTION = SUPPRIMER LE CARTOUCHE PAR DEFAUT PRESENT DANS LE TEMPLATE ###
	NewDwg.ActiveSheet.TitleBlock.Delete
	'# ACTION = SUPPRIMER LE SYMBOLE "Cadre - Informations Générales"
	Dim oSketchedSymbolDef As SketchedSymbol
	For Each oSketchedSymbolDef In NewDwg.ActiveSheet.SketchedSymbols
		If oSketchedSymbolDef.Name = "Cadre - Informations Générales" Then
			oSketchedSymbolDef.Delete 'It will delete all the sketched symbols
		End If
	Next
	'# ACTION = SUPPRIMER LE SYMBOLE "Title Block - FR-EN - Support"
	For Each oSketchedSymbolDef In NewDwg.ActiveSheet.SketchedSymbols
		If oSketchedSymbolDef.Name = "Title Block - FR-EN - Support" Then
			oSketchedSymbolDef.Delete 'It will delete all the sketched symbols
		End If
	Next

	'#### PRÉPARATION DU TEMPLATE POUR LA PAGE DE GARDE.
	'## INSERTION DES ÉLÉMENTS UTILES À LA PAGE DE GARDE (CARTOUCHE, SYMBOLES D'ESQUISSE...)
	'# ACTION = INSERER LE CARTOUCHE "Cover page" ###
	NewDwg.ActiveSheet.AddTitleBlock("Title Block KTSN - FR-EN - Cover Page")

	'#### INSERTION DE LA LISTE INVENTAIRE DE LA LIASSE DE PLAN
	'### OBJECTIF : PLACER LA LISTE SUR LE BORD DROIT DE LA LARGEUR DE LA FEUILLE (Horizontalement).
	'### OBJECTIF : PLACER LA LISTE À 125 MM DE HAUTEUR (Verticalement).
	'## DÉCLARATION DE LA VARIABLE "oTG" (OBJET TRANSIENT GEOMETRY) POUR ACCEDER AUX OUTILS GÉOMÉTRIE TRANSITOIRE.
	Dim oTG As Inventor.TransientGeometry = ThisApplication.TransientGeometry 	'oTG = Objet Transient Geometry

	'## DÉCLARATION DE LA VARIABLE "ListCenter" QUI POSITIONNE UN POINT VIRTUEL 2D SUIVANT LES OBJECTIFS.
	Dim ListCenter As Inventor.Point2d = oTG.CreatePoint2d(0, 0)

	'## DÉCLARATION DE LA VARIABLE "oSketchedSymbolDef" QUI SERA ÉGALE AU SYMBOLE "Cadre - Inventory List"
	Dim oSketchedSymbolDefInvList As SketchedSymbolDefinition
	oSketchedSymbolDefInvList = NewDwg.SketchedSymbolDefinitions.Item("Cadre - Inventory List")

	'# ACTION = INSERER LE SYMBOLE D'ESQUISSE "Cadre - Inventory List" ###
	'"Cadre - Inventory List"
	Dim oSketchedSymbol As SketchedSymbol
	oSketchedSymbol = NewDwg.ActiveSheet.SketchedSymbols.Add(oSketchedSymbolDefInvList, ListCenter)
	']

End Sub

 

I have to make the drawing for a welded assembly.
I create an iLogic rule in my iam file.

Despite your help, the last command does not work.
I want to insert the sketch symbol "Frame - Inventory List".

Unfortunately, my code returns the following error message:

 

Message d'erreur
Erreur de règle: Règle - MISE EN PLAN, dans le document Steam Coil - Front Header.iam

Paramètre incorrect. (Exception de HRESULT : 0x80070057 (E_INVALIDARG))


Plus d'infos
System.ArgumentException: Paramètre incorrect. (Exception de HRESULT : 0x80070057 (E_INVALIDARG))
à System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
à Inventor.SketchedSymbols.Add(Object SketchedSymbolDefinition, Point2d Position, Double Rotation, Double Scale, Object PromptStrings)
à ThisRule.Main()
à Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
à iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Can you see where my error is?

 

 

0 Likes
Message 5 of 5

A.Acheson
Mentor
Mentor

Can you the symbol exist in the drawing and the defintion name matches exactly?

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes