Jump to content
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

 

 

creakesiv, Rahul R, pohan and 1 other like this

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...