Placing Sketch Symbol with Prompted Entry using iLogic

Placing Sketch Symbol with Prompted Entry using iLogic

swalroth8KYHK
Contributor Contributor
1,514 Views
6 Replies
Message 1 of 7

Placing Sketch Symbol with Prompted Entry using iLogic

swalroth8KYHK
Contributor
Contributor

This is probably a stupid question, but I just can't get it working.

I'm trying to place a view label and fill out 4 Prompted Entries with information gathered from various sources.

 

Dim vNum As Integer
Dim sdNum As String
Dim fName As String
Dim oMaterial As String

'Dim sPromptString(3) As String
Dim sPromptString(0) As String
'Dim sPromptString As String()

'oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item("Label - View - v2") oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item("Label - Door/Window") 'sPromptString = {vNum, sdNum, fName, oMaterial} sPromptString = {"A"} 'MsgBox(sPromptString(0) & " - " & sPromptString(1) & " - " & sPromptString(2) & " - " & sPromptString(3), okay, "Debug") MsgBox(sPromptString(0), okay, "Debug") oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oPoint2, 0, 1, sPromptString)

 

I dropped it back to another label that has only one Prompted Entry to test, and it still won't fill it out.  If I pick a symbol with no Prompted Entries, and change it to Nothing, it works fine, but no matter what I try I keep getting an error:

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

In both cases the Message Box shows all the information I want as expected, the first symbol "Label - View - v2" has 4 entries and the second "Label - Door/Window" has 1.

0 Likes
Accepted solutions (1)
1,515 Views
6 Replies
Replies (6)
Message 2 of 7

Sergio.D.Suárez
Mentor
Mentor

Here is an example with a sketch symbol insert with 4 entries.

 

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet

Dim oSymDef As SketchedSymbolDefinition = oDoc.SketchedSymbolDefinitions.Item("Label - Door/Window")
Dim sPromptStrings(3) As String 
sPromptStrings(0) = "Value A"
sPromptStrings(1) = "Value B"
sPromptStrings(2) = "Value C"
sPromptStrings(3) = "Value D"

Dim oPosition As Point2d =  ThisApplication.TransientGeometry.CreatePoint2d(10,15)

Dim oSymbol As SketchedSymbol
oSymbol = oSheet.SketchedSymbols.Add(oSymDef, oPosition,0,1,sPromptStrings)


I hope it is useful for you. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 3 of 7

swalroth8KYHK
Contributor
Contributor

Your code works just fine, but for some reason I just cannot get mine to.  As far as I can tell this is exactly the same.

 

 

Dim fPath As String = ThisDoc.Path
Dim fNames() As String = System.IO.Directory.GetFiles(fPath, "*.ipt")
Dim fName As String
Dim pType As String
Dim sdNum As String
Dim StartTime = Now

Dim oPartDocPath As String
Dim oPartDoc As PartDocument
Dim oDrawDoc As DrawingDocument
Dim oSheet As Object
Dim oTG As TransientGeometry
Dim oPoint1 As Point2d
Dim oPoint2 As Point2d
Dim oBaseView As Object
Dim oViewModelDoc As Object
Dim oSketchedSymbolDef As SketchedSymbolDefinition
Dim oSketchedSymbol As SketchedSymbol
Dim sPromptString(3) As String
Dim xPos As Integer
Dim vNum As Integer
Dim oMaterial As String

xPos = 5
vNum = 1
sdNum = iProperties.Value("Project", "Stock Number") & ".0"

For Each fName In fNames
fName = IO.Path.GetFileName(fName)
pType = Mid(fName, 11, 2)
If pType = "CB" Then
	oPartDocPath = fPath + "\" + fName
	oPartDoc = ThisApplication.Documents.Open(oPartDocPath, False)
	oDrawDoc = ThisDoc.Document 
	oSheet = oDrawDoc.ActiveSheet
	oTG = ThisApplication.TransientGeometry
	oPoint1 = oTG.CreatePoint2d(xPos, - 50)
	oPoint2 = oTG.CreatePoint2d(xPos, - 80)
	oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, 1 / 8, ViewOrientationTypeEnum.kIsoTopRightViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "Default")
	oPartDoc.Close
	oViewModelDoc = oBaseView.ReferencedDocumentDescriptor.ReferencedDocument
	oMaterial = oViewModelDoc.PropertySets.Item("Design Tracking Properties").Item("Material").Value
	xPos = xPos + 30
	oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item("Label - View - v2")
	sPromptString(0) = vNum
	sPromptString(1) = sdNum
	sPromptString(2) = fName
	sPromptString(3) = oMaterial
	'MsgBox(sPromptString(0) & " - " & sPromptString(1) & " - " & sPromptString(2) & " - " & sPromptString(3), okay, "Debug")
	oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oPoint2, 0, 1, sPromptString)
	vNum = vNum + 1
End If
Next

 

 

0 Likes
Message 4 of 7

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

The codes are not the same, at first impression the first visible error is that it has sized the sheet as an object.

 

Dim fPath As String = ThisDoc.Path
Dim fNames() As String = System.IO.Directory.GetFiles(fPath, "*.ipt")
Dim fName As String
Dim pType As String
Dim sdNum As String
Dim StartTime = Now

Dim oPartDocPath As String
Dim oPartDoc As PartDocument
Dim oDrawDoc As DrawingDocument
Dim oSheet As Object
Dim oTG As TransientGeometry
Dim oPoint1 As Point2d
Dim oPoint2 As Point2d
Dim oBaseView As Object
Dim oViewModelDoc As Object
Dim oSketchedSymbolDef As SketchedSymbolDefinition
Dim oSketchedSymbol As SketchedSymbol
Dim sPromptString(3) As String
Dim xPos As Integer
Dim vNum As Integer
Dim oMaterial As String

xPos = 5
vNum = 1
sdNum = iProperties.Value("Project", "Stock Number") & ".0"

For Each fName In fNames
fName = IO.Path.GetFileName(fName)
pType = Mid(fName, 11, 2)
If pType = "CB" Then
	oPartDocPath = fPath + "\" + fName
	oPartDoc = ThisApplication.Documents.Open(oPartDocPath, False)
	oDrawDoc = ThisDoc.Document 
	oSheet = oDrawDoc.ActiveSheet
	oTG = ThisApplication.TransientGeometry
	oPoint1 = oTG.CreatePoint2d(xPos, - 50)
	oPoint2 = oTG.CreatePoint2d(xPos, - 80)
	oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, 1 / 8, ViewOrientationTypeEnum.kIsoTopRightViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "Default")
	oPartDoc.Close
	oViewModelDoc = oBaseView.ReferencedDocumentDescriptor.ReferencedDocument
	oMaterial = oViewModelDoc.PropertySets.Item("Design Tracking Properties").Item("Material").Value
	xPos = xPos + 30
	oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item("Label - View - v2")
	sPromptString(0) = vNum
	sPromptString(1) = sdNum
	sPromptString(2) = fName
	sPromptString(3) = oMaterial
	'MsgBox(sPromptString(0) & " - " & sPromptString(1) & " - " & sPromptString(2) & " - " & sPromptString(3), okay, "Debug")
	oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oPoint2, 0, 1, sPromptString)
	vNum = vNum + 1
End If
Next

I do not have your files so I can not prove the complete code but I can show you that this simple code below works.

 

oDrawDoc = ThisDoc.Document 
Dim oSheet As Sheet 
oSheet = oDrawDoc.ActiveSheet
oTG = ThisApplication.TransientGeometry
oPoint2 = oTG.CreatePoint2d(10,8)
oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item("Label - View - v2")
Dim sPromptString(3) As String 
sPromptString(0) = "vNum"
sPromptString(1) = "sdNum"
sPromptString(2) = "fName"
sPromptString(3) = "oMaterial"
oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oPoint2, 0, 1, sPromptString)


In the case of your punctual code, it may be the case that you have more errors that you should debug. If you know that a code sequence works, the error is probably somewhere else. 

Here you have two other possible errors

Dim oBaseView As Object 

Dim oViewModelDoc As Object 

 

They should be

Dim oBaseView As DrawingView
Dim oViewModelDoc As Document

regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 5 of 7

swalroth8KYHK
Contributor
Contributor

I knew it would be something simple, thanks so much.  It works exactly as intended now.

0 Likes
Message 6 of 7

Sergio.D.Suárez
Mentor
Mentor

A little advice that may be useful for you later.
When you believe that part of the code is OK, and you do not know the location of the error, try to insert a simple message box MessageBox.Show ("Message", "Title") of your ilogic, locate it at the beginning of the code. Execute the file, and if the box appears, the error will be lower. Now locate the message box and place it below in your program. Re-execute the code and perform this procedure until you find the possible place where the error is generated. Regards!


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 7 of 7

swalroth8KYHK
Contributor
Contributor

To be fair, I had done as much with a message box immediately before the line adding the sketch symbol.  Everything else ran smoothly.  I was even able to place a symbol that had no prompted entries with the same code by changing only the symbol name.

0 Likes