Jump to content
  • Announcements

    • Rahul Ponginan

      Please click here for a short but important announcement   03/26/17

      Dear Users Our Commercial and Academic users around the world can use these same forums here as before i.e. the Altair Support Forum , Commercial users from India with solver queries can go to the Solver Forum for India Commercial Users , Academic Users from India and AOC India Participants are requested to go to the Forum for India Academic Users and AOC India Participants , We will be tending to all queries in all the forums promptly as before, thank you for your understanding. 
Sign in to follow this  
creakesiv

Trying to create first Tcl/Tk macro

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

 

 

Share this post


Link to post
Share on other sites
7 hours ago, tinh said:

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!

tinh likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×