Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Retrieve SketchedSymbol position in a IDW - iLogic

7 REPLIES 7
Reply
Message 1 of 8
tuliobarata
1592 Views, 7 Replies

Retrieve SketchedSymbol position in a IDW - iLogic

Good morning all,

 

Some months ago I created (with a good help from here of course) an iLogic code that creates all my notes that I use in my drawings, linked to a form. A good tool the made my work a little easy. Now I wanna make an update on it, but I searched here and in the programming help, but I didn't make it 😞

 

In my code I create a sketchedSymbol and then some textBoxes with my notes, but before that I erase all the Symbols in all sheets and then the main Symbol itself. Then I create again the symbol and textBox in a specific point of my Sheet. So, everytime that I need to update my Notes, it goes to that point of the sheet, it's not a problem, but it's annoying have to move them always to the correct place.  And i  can't use a specific final point for the notes because it may change according to the drawing.

So, my idea is: 

If the Symbol is already created, how can I get its position ?

I create the points with TransientGemometry and then CreatePoint2D, but I dont know how to retrieve these points, even if that is possible.

 

The code I use is that below (I just erase the notes because it was too big, this is just the main code creating the stuffs).

 

Thanks all!.

Túlio Barata

 

    ' Set a reference to the drawing document.    ' This assumes a drawing document is active.    Dim oDrawDoc As DrawingDocument
     oDrawDoc = ThisApplication.ActiveDocument
'Update the document    oDrawDoc.Update

'apaga o symbol existente em cada sheet    Dim oSheets As Sheets
        oSheets = oDrawDoc.Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
Dim oSymbol As SketchedSymbol
Dim oSymbols As SketchedSymbols

For Each oSheet In oSheets
    For Each oSymbol In oSheet.SketchedSymbols
    If oSymbol.Definition.Name = "Notas Solution" Then
    oSymbol.Delete
    Else 
    End If
    Next
Next

'apaga o symbol do IDWDim oSketchedSymbolDef As SketchedSymbolDefinition    
    For Each oSketchedSymbolDef  In oDrawDoc.SketchedSymbolDefinitions
    If oSketchedSymbolDef.Name = "Notas Solution" Then
    oSketchedSymbolDef.Delete
    Else 
    End If
    Next

'Cria novamente o symbol em branco no IDW      oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Add("Notas Solution")

'Abre o symbol para edição Dim oSketch As DrawingSketch    
Call oSketchedSymbolDef.Edit(oSketch)


Dim oTG As TransientGeometry
     oTG = ThisApplication.TransientGeometry
     
Dim dYCoord,dXCoord,dXCoord_,dY00,dY11,dY12 As Double
    'coordenada inicial de posicionamento em Y    dYCoord = -5
    'coordenada inicial de posicionamento em X    dXCoord = 0
    'deslocamento em X das notas no idioma secundario    dXCoord_ = dXCoord+0
    'espaçamento inicial entre o titulo e a primeira linha da nota    dY00 = 0.3
    'espaçamento entre as linhas do idioma primario    dY11 = 0.1
    'espaçamento entre as linhas do idioma secundario    dY12 = 0.05   





Dim oTextBox As TextBox
'Titulo ID1    If Parameter("ref_TipoNota") = "0 - Solution" Then
    oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(dXCoord, dYCoord), Tit_ID1,"COMUMT3")
    Else
    oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(dXCoord, dYCoord), "","COMUMT3")
    End If
    'Titulo ID2     If  Parameter("ref_ID") = True Then
    If Parameter("ref_TipoNota") = "0 - Solution" Then
            dYCoord = dYCoord - (oTextBox.FittedTextHeight + dY12)
    oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(dXCoord_, dYCoord), Tit_ID2,"NOTA_L2")
    Else
            dYCoord = dYCoord - (oTextBox.FittedTextHeight + dY12)
    oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(dXCoord_, dYCoord), "","NOTA_L2")
    End If
    End If
    
'-----------------------------------------------------------------------------------------------------------------------            '1º Nota ID1    dYCoord = dYCoord - (oTextBox.FittedTextHeight + dY00)
    If Not Parameter("Nota1_ID1")="" Then
    oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(dXCoord, dYCoord), Parameter("Nota1_ID1"),"NOTA_L1")
    End If 
    '1º Nota ID2    If  Parameter("ref_ID") = True  And Parameter("Nota1_ID2") <> "" Then
    dYCoord = dYCoord - (oTextBox.FittedTextHeight + dY12)
    oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(dXCoord_, dYCoord), Parameter("Nota1_ID2"),"NOTA_L2")
    End If
        
'-----------------------------------------------------------------------------------------------------------------------             '2º Nota ID1    dYCoord = dYCoord - (oTextBox.FittedTextHeight + dY11)
    If Not Parameter("Nota2_ID1")="" Then
    oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(dXCoord, dYCoord), Parameter("Nota2_ID1"),"NOTA_L1")
    End If 
    '2º Nota ID2    If  Parameter("ref_ID") = True  And Parameter("Nota2_ID2") <> "" Then
    dYCoord = dYCoord - (oTextBox.FittedTextHeight + dY12)
    oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(dXCoord_, dYCoord), Parameter("Nota2_ID2"),"NOTA_L2")
    End If
    


'fecha a edição o symbolCall oSketchedSymbolDef.ExitEdit(True)
   
  
 oSheet = oDrawDoc.ActiveSheet
   
'adiciona o symbol no sheet Dim oSketchedSymbol As SketchedSymbol    
 oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oTG.CreatePoint2d(0, -2), (0), 1)
 





 

IV 2013
7 REPLIES 7
Message 2 of 8
tsreagan
in reply to: tuliobarata

The portion of your code that creates the sketch symbol looks like spanish.

because of this it is hard to tell off hand,  but there are a number of coords called out there.

 

I would have to see the symbol and the specific point you want to find in relation to the symbol geometry, then compare that to your code and figure out the coords of the point you want.
Does the position change based on the other sheet content, the sheet size, or a mixture?

 

You can add code that will position it based on sheet size, and even adjust it's position based on drawing views, boms, etc, if their position and size is known at the time.

 

Why are you deleteing and recreating,  could you not update the table info without deleteing the originals?

 

I developed an auto drawing rule that creates drawings for all parts in an assembly.

It figures out the part size, and proportions, then generates sheets and views based on each individual part.

So what you want to do should be automatable based on sheet content, if you want to go through the trouble.

 

 

I may have missed what you want exactly, but hopefully this will help to get you further down your path.

 

T.S.

 

 

'This is not what you need, but it does demonstrate getting size and points, and moving sheet objects with iLogic.

'This code figures out the dimensions of the parts list and places it (left justified and bottom of sheet).

 

Dim PartsBox As Box2d

PartsBox = oPartsList.Rangebox

Dim ptMin As Point2d = PartsBox.MinPoint

Dim ptMax As Point2d = PartsBox.MaxPoint

 

'MsgBox (ptMax.X & " " & ptMin.Y)

 

PListLength = (ptMax.X - ptMin.X)

PListWidth = (ptMax.Y - ptMin.Y)

 

'MsgBox (PListLength & " " & PListWidth)

 

 

V7WC = (WBorderOffset / 2) + .5803

V7HC = (HBorderOffset / 2) + (PListWidth) + .5803

oPoint7 = ThisApplication.TransientGeometry.CreatePoint2d(V7WC, V7HC)

oPartsList.Position = oPoint7

Message 3 of 8
tuliobarata
in reply to: tsreagan

thanks for the reply tsreagan !

 

While I'm doing some stuffs ill take a look in your code, to see if i cant get something from it!

Below, the answers for ur questions:

 

The portion of your code that creates the sketch symbol looks like spanish.

because of this it is hard to tell off hand,  but there are a number of coords called out there.

Really sorry, I just forgot to change some comments I've made, some are in Portuguese.

 

Does the position change based on the other sheet content, the sheet size, or a mixture?

It changes according to the Sheet used, some stamps, BOM and even some different note that we use sometimes, because of that, the position almost never will be the same. So, I wanna put the Symbol by first time in somewhere like dYCoord = -5 and dXCoord = 0 (in the left bottom of the sheet), the I move it manually to the correct place. I wanna then, when I change something in the note, it gets the position that I manually put and keep the note there.

 

Why are you deleteing and recreating,  could you not update the table info without deleteing the originals?

Actually i did that because I dont know other way to make that work, all the references I've found were like that. I didn't find a way to update the textBoxes I've create, so everytime i need to update, the code erase everything and creating a new one with the data that are in some parameters.

 

So what you want to do should be automatable based on sheet content, if you want to go through the trouble.

I tried to think in something to get a standard position, but I didn't find any way of doing that. Here it can change the position by may ways, it's annoying.

 

In you code, i can see that you get the BOM points, max and min. I would like to know if I could get something like that, but from a Symbol. If I could get somepoint from a Symbol with an unique name, that would work great, even deleting and recreating the symbol every time. THe problem is what code/syntax  that gets the point from this Symbol.

 

 

Thanks very much for the help !

 

Túlio Barata

 

IV 2013
Message 4 of 8
tsreagan
in reply to: tuliobarata

Should be easy to accomplish.

 

The Initial coords are prolly these two lines

'coordenada inicial de posicionamento em Y dYCoord = -5

'coordenada inicial de posicionamento em X dXCoord = 0

 

Ok,  I see where your going...  now you manually move it,  and need those new coords later.

This should be pretty easy to accomplish.

 

 

The logic will be to create a point object, and assign it to the new position.

  Now is -5,0 the origin of the sketch symbol, or just a point in the sketch.  If it's the origin, we should be a able to grab that pretty easy and assign it to a point paramater, and then that will update when you move the graphics around.

 

I will look into the exact syntax when I get a chance

 

If your lucky someone will chime in with a better way to updated your tables without moving anything.

 

T.S.

Message 5 of 8
tuliobarata
in reply to: tsreagan

ok, thanks tsreagan!

 

Ill keep trying here while that!

 

 

Thanks

Túlio Barata

IV 2013
Message 6 of 8
tsreagan
in reply to: tuliobarata

Here is the code to get the origin of your Symbol.

 

Dim oDrawDoc As DrawingDocument

oDrawDoc = ThisApplication.ActiveDocument

oDrawDoc.Update oSheets = oDrawDoc.Sheets

Dim oSheet As Sheet

Dim oViews As DrawingViews

Dim oView As DrawingView

Dim oSymbol As SketchedSymbol

Dim oSymbols As SketchedSymbols

 

For Each oSheet In oSheets

     For Each oSymbol In oSheet.SketchedSymbols

          If oSymbol.Definition.Name = "TestSymbol" Then

              Dim oSymbPoint As Point2d

              oSymbPoint = oSymbol.Position

              MsgBox(oSymbPoint.x & " " & oSymbPoint.y)

          End If

     Next

Next

Message 7 of 8
tuliobarata
in reply to: tsreagan

Thanks very much tsreagan! That was exactly what I was looking for!

 

Now with this code this tool is a little easy to use!  It gets the correct position of the block and then recreate it in the same position.Great!

 

One last doubt, is that possible ? 🙂

 

Is there a way to create this Symbol with the insertion point in the left top corner ? Now it creates from the center point, a better way would be from top left so the Symbol height would go down when I add new lines. I tried in the SketchedSymbols.Add but there is only position, rotation and scale. And in the SketchedSymbolDefinitions i didnt find anyway to put this orientation.

 

 

Thanks!

Túlio Barata

IV 2013
Message 8 of 8
tsreagan
in reply to: tuliobarata

Glad you got the first part to work fine.

 

I tried to rangebox the symbol but that routine does not work on symbols.

 

If your creating the symbol with iLogic,  you can figure its dims based on the line generation code,  and then add half the height, and subtract half the width, to get the top left corner of the linework.

 

If your are creating it graphically the origin will be the center of the line work,  you may be able to add hidden lines to re-adjust the origin that way

 

If we back up to the sketch symbol definition object we can then get to the base sketch in a read only mode.

In the programming help file search for  SketchedSymbolDefinition Object

 

If the upper left portion of the sketch has a point object (ie... end of line, point, end of arc, etc...) then you can pull the sketch object from the sketchedsymboldefinition, then iterate through the sketch points making up the sketch, comparing the x and y of the sketch points, and find the highest y point and left most x point. 

 

T.S.

 

 

 

 

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

Post to forums  

Autodesk Design & Make Report