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: 

Replacing a Sketch Block using iLogic and iPart Parameters

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
zpickA9TX3
1468 Views, 7 Replies

Replacing a Sketch Block using iLogic and iPart Parameters

Hi,

 

Is there a way to use iLogic to replace a block used in a sketch so that each block corresponds with a different part via iPart?

 

I know my phrasing of my question is poor so here is an example of what I am looking for:

 

I have 26 cubes for each of the 26 letters in the alphabet. Each of the cubes are the same exact dimensions but the only change is that each cube has a different letter. I have created each letter as a sketch block which will be extruded from the front top face (the font that I tried to use had issues with the emboss feature so I had to recreate the letters myself). To make things easier, I am using iParts to streamline my designing. Is there a way to define a parameter using iParts or iLogic so that say the sketch block with letter A is used with cube 1, the block with letter B used with cube 2 and so on?

 

Thank you to anyone who is able to provide assistance,

Zach

7 REPLIES 7
Message 2 of 8
johnsonshiue
in reply to: zpickA9TX3

Hi! I don't believe there is a workflow to replace sketch blocks. If there was no manual workflow, more than likely the iLogic code would not exist. Also, iPart is designed to generate library parts for reuse purpose.

Forget about sketch block for a second. If I understood your request correctly, you would like to drive the sketch text using iLogic, right? There is a workflow you may consider. Text parameters are not supported on iPart author table. But, iProperty is allowed. Here is what you can do.

 

1) Create a custom iProperty called "Alphabet."

2) Add "Alphabet" as a column on the iPart table.

3) For each member row, enter the desirable letter.

4) Create an iLogic rule assigning this custom property to a pre-defined text parameter. Enable property change/parameter change trigger.

5) In the text sketch, reference the text parameter.

6) Generate the members.

 

Please try it out and see if it works for you.

Many thanks!

 



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
Message 3 of 8
zpickA9TX3
in reply to: johnsonshiue

Hi Johnson,

 

Thank you for your response. I should clarify that the each letter is actually geometry. I was originally going to make a shx text in AutoCAD however curves and lines came out very jagged when I tried the font out hence to why I am creating sketch blocks for each individual letter. In other words, I am not using sketch text, rather actual geometry.

 

-Zach

Screenshot (31).png

Message 4 of 8
johnsonshiue
in reply to: zpickA9TX3

Hi! Then I don't have a better approach. You will need to do it one by one. I am not aware of a workflow swapping out sketch blocks or profiles without failures.

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
Message 5 of 8
lena.talkhina
in reply to: zpickA9TX3

Hello @zpickA9TX3  !

Great to see you here on Inventor Customization Forum.

Did you find a solution?
If yes, please click on the "Accept as Solution" button as then also other community users can easily find and benefit from the information.
If not please don't hesitate to give an update here in your topic so all members know what ́s the progression on your question is and what might be helpful to achieve what you ́re looking for. 🙂

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.



Лена Талхина/Lena Talkhina
Менеджер Сообщества - Русский/Community Manager - Russian

Message 6 of 8
WCrihfield
in reply to: zpickA9TX3

  • The Insertion point within both sketch blocks would have to be in the same exact place in relation to its overall geometry, so when it is replaced, you don't have to reposition it.
  • The X,Y, & Z orientation of both sketch blocks should be set up the same way, to avoid having to rotate, mirror, or translate the sketch block when replaced.
  • The sketch within the part that is using the sketch block, should be 'shared' rather than consumed by the extrude feature.
  • The part which is using the sketch block for its extrusion feature, should at least be 'rolled back' to before the extrusion feature, before the sketch block replace function is carried out, to help avoid errors, then rolled back forward after the replacement.
    • However, recreating your extrude feature (and any further geometry manipulation connected to that face) using iLogic, after replacing the sketch, would most likely result in a better reduction in possible errors.

I haven't tried replacing the sketch under an existing extrusion feature before, but I do regularly update older files, by totally deleting all unused, and replacing all used Borders, Border Definitions, Title Blocks, Title Block Definitions, Sketched Symbols, & Sketched Symbol Definitions.

Wesley Crihfield

EESignature

Message 7 of 8
zpickA9TX3
in reply to: WCrihfield

After weeks of searching the forums and scavenging the help documents, I finally got things working exactly how I wanted it to work. I have attached the code I developed so that others can use it as a reference. I ended up having to use a combination of VBA and iLogic to get it all working. Because the face for which I wanted the block to be on was created by a loft feature, you will see that the VBA code references the loft as the face to make the planar sketch. In addition, some code is used to select the appropriate face on the loft feature. One can redefine this to fit their needs.


To get this working with iParts, I defined 2 User Parameters called BlockName and BlockName_Index. BlockName_Index runs via iLogic code to change the value of the BlockName parameter. BlockName is implemented into the VBA code so that the code would select the block to place based on the values defined for BlockName. BlockName_Index can be changed via iParts table so that each iPart member can use a different block. For example, if BlockName_Index is 1 ul, the value of BlockName will be A, 2 ul will be B, and so on. The BlockName values can be changed in the iLogic code to match the name of the particular block. BlockName_Index must keep the format of # ul in order for this all to work. Depending on how many iPart members a person has, one can match the iLogic code to their specific needs.


Another User Parameter, d65, was defined for extruding the block. One can change the name of this parameter in the VBA code to match another user parameter of their choosing. This parameter can be implemented into an iParts table so that different members can have different extrusion values to fit their needs.


Some errors that occur are as follows:

  • For whatever reason, the block would be placed flipped. For example, the letter A would be flipped upside down when there should be no flip what so ever. I feel that this could be down to how I imported the blocks into the document but if someone can find an error in the code causing this, please feel free to respond!
  • I was hoping to have the iLogic that defines the BlockName parameter update automatically when I change between iPart members. I tried to implement the iTrigger functionality of iLogic but this seems to do absolutely nothing. If someone can come up with a solution to this, I would be willing to test it out and let you know if it works. Please send me a private message if you would like to see if this issue is document specific.

I hope that this helps anyone who is looking to automate the same functionality. Keep in mind that this code automates this process so if any values need to be changed after this code runs, one needs to undo or delete the actions executed by the code.

 

-Zach

 

VBA Code:

Option Explicit

Public Sub InsertSketchBlockDefinition()
    ' Set a reference to the part document.
    ' This assumes a part document is active.
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument

    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oPartDoc.ComponentDefinition

    ' Create a new sketch on the X-Y work plane.
    'Dim oSketch As PlanarSketch
    'Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(4))
    Dim oLoft As LoftFeatures
    Set oLoft = oCompDef.Features.LoftFeatures
    Dim oFaces As Faces
    
    'This can be changed to .SideFaces, .EndFaces, or .StartFaces
    'But .Faces will let you choose between all faces
    Set oFaces = oLoft.Item(1).Faces
    
    Dim oSketch As PlanarSketch

    'Put a sketch on the first face (1) - change to suit
    Set oSketch = oCompDef.Sketches.AddWithOrientation(oFaces(5), oCompDef.WorkAxes.Item(2), True, True, oCompDef.WorkPoints(1))

    'Get User Parameter
    Dim oParams As Parameters
    Set oParams = oCompDef.Parameters
    Dim oUserParams As UserParameters
    Set oUserParams = oParams.UserParameters

    ' Set a reference to the definition named "A"
    Dim oSketchBlockDef As SketchBlockDefinition
    Set oSketchBlockDef = oCompDef.SketchBlockDefinitions.Item(oUserParams.Item("BlockName").Value)

    Dim oPosition As Point2d
    Set oPosition = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)

    ' Insert the sketch block definition
    Call oSketch.SketchBlocks.AddByDefinition(oSketchBlockDef, oPosition).Explode
    
    Dim oProfile As Profile
    Set oProfile = oSketch.Profiles.AddForSolid

    ' Extrude the sketch.
    Dim oExtrudeDef As ExtrudeDefinition
    Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
    Call oExtrudeDef.SetDistanceExtent("d65", kPositiveExtentDirection)
    Dim oExtrude As ExtrudeFeature
    Set oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
    
End Sub

 

iLogic Code:

iLogicVb.UpdateWhenDone = True

Select Case BlockName_Index
	
	Case 1
	Parameter("BlockName") = "A"
	Case 2
	Parameter("BlockName") = "B"
	Case 3
	Parameter("BlockName") = "C"
	Case 4
	Parameter("BlockName") = "D"
	Case 5
	Parameter("BlockName") = "E"
	Case 6
	Parameter("BlockName") = "F"
	Case 7
	Parameter("BlockName") = "G"
	Case 8
	Parameter("BlockName") = "H"
	Case 9
	Parameter("BlockName") = "I"
	Case 10
	Parameter("BlockName") = "J"
	Case 11
	Parameter("BlockName") = "K"
	Case 12
	Parameter("BlockName") = "L"
	Case 13
	Parameter("BlockName") = "M"
	Case 14
	Parameter("BlockName") = "N"
	Case 15
	Parameter("BlockName") = "O"
	Case 16
	Parameter("BlockName") = "P"
	Case 17
	Parameter("BlockName") = "Q"
	Case 18
	Parameter("BlockName") = "R"
	Case 19
	Parameter("BlockName") = "S"
	Case 20
	Parameter("BlockName") = "T"
	Case 21
	Parameter("BlockName") = "U"
	Case 22
	Parameter("BlockName") = "V"
	Case 23
	Parameter("BlockName") = "W"
	Case 24
	Parameter("BlockName") = "X"
	Case 25
	Parameter("BlockName") = "Y"
	Case 26
	Parameter("BlockName") = "Z"

End Select

 

Message 8 of 8
lena.talkhina
in reply to: zpickA9TX3

This is an awesome respond!
I know find a solution is not easy sometimes but I am so happy you finally find it.
Thanks for sharing this with us.

Happy to have you in our community!

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.



Лена Талхина/Lena Talkhina
Менеджер Сообщества - Русский/Community Manager - Russian

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

Post to forums  

Autodesk Design & Make Report