🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

Trying to create first Tcl/Tk macro

User: "Altair Forum User"
Altair Employee
Updated by Altair Forum User

Hi, 

I am currently working on creating a macro just to learn the process. I want this macro to check the components and see if a component labeled '^2D' exists. If it does not, I want the macro to create this component. The macro will then move all 2D quad and tria elements to this collector. The reason for this is I like to save my 2D mesh in a collector that I can turn export off before output to a .inp.

 

I have used this code to verify that I am able to create the collector and move the elements:

*beginmacro('Move2D')
    *createentity(comps,name=^2D)
    *createmark(element,1) 'by config' tria3, tria6, quad4, quad8
    *movemark(elements,1,'^2D')
*endmacro()

 

However I am having trouble when attempting to do a loop check. I am 99% sure that my formatting for Tcl is completely wrong (I just began learning the code yesterday). When attempting to load the userpage.mac hyperworks freezes with the code how it is. 

*beginmacro('Move2D')
    set exists 'False'
    set entitylist (hm_entitylist comps name)
    foreach title $entitylist {
        if {$title == '^2D'} {
            set exists 'True'
            return
        }
     if {$exists == 'True'} {
    *createentity(comps,name=^2D)
    }
    *createmark(element,1) 'by config' tria3, tria6, quad4, quad8
    *movemark(elements,1,'^2D')
    }
*endmacro()

 

Thank you in advance for any help,

-Clay

Find more posts tagged with

Sort by:
1 - 2 of 21
    User: "tinh"
    Altair Community Member
    Updated by tinh

    Hi,

    it is simpler if you write a *.tcl file because tcl commands are not used directly in macro file, example file <Move2dElemsToComp.tcl> :
     

     proc ::p_Move2dElemsToComp {{CompName ^2D}} {      if {![hm_entityinfo exist comps $CompName -byname]} {           *collectorcreateonly comps $CompName '' 11      }      *createmark elems 1 'by config' tria3 quad4 tria6 quad8      if {[hm_marklength elems 1]} {*movemark elems 1 $CompName} } ::p_Move2dElemsToComp

     

    Now your macro will be:

     

    *beginmacro('Move2D')

         *evaltclscript('C:\Users\demo\Documents\Move2dElemsToComp.tcl',0)

    *endmacro

     

     

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    Hi,

    it is simpler if you write a *.tcl file because tcl commands are not used directly in macro file, example file <Move2dElemsToComp.tcl> :
     

      proc ::p_Move2dElemsToComp {{CompName ^2D}} {      if {![hm_entityinfo exist comps $CompName -byname]} {           *collectorcreateonly comps $CompName '' 11      }      *createmark elems 1 'by config' tria3 quad4 tria6 quad8      if {[hm_marklength elems 1]} {*movemark elems 1 $CompName} } ::p_Move2dElemsToComp

     

    Now your macro will be:

     

    *beginmacro('Move2D')

         *evaltclscript('C:\Users\demo\Documents\Move2dElemsToComp.tcl',0)

    *endmacro

     

     

     

    This is perfect, thank you so much!