Challenge

Week - 8 - Creating component and property

OBJECTIVE:

  • To ask the user to enter the name of a component and its thickness
  • To write a code that will automatically create components and assign thickness to it
  • The code should decide on its own what type of collector should be created depending on the user profile/deck.
  • According to the deck, the code should decide, whether a property needs to be created or not.
  • To auto colour the created component and property.

PROCEDURE:

  • Firstly, create a window with a button and two text fields to get the component name and thickness.
  • Then we need to create a code that will determine the current solver deck and create a component name and assign the property card to the component.
  • The code should handle null cases and should warn the user if the component name exists or not.
  • Here, inside the if statement, the *hm_entityinfo command is used to prevent null cases.
  • The hm_getsolver command is used to find the name of the solver deck.
  • *createentity is used to create component and property cards.

CODE:

set a .window
catch {destroy $a}
toplevel $a -class Toplevel
wm title $a "COMPONENT CREATION"
wm geometry $a 300x200+100+100
wm resizable $a 0 0
wm deiconify $a 


label $a.label1 -text "Component" -bg grey -font {times 12 bold}; place $a.label1 -x 25 -y 20 -width 100 -height 30
label $a.label2 -text "Thickness" -bg grey -font {times 12 bold}; place $a.label2 -x 25 -y 70 -width 100 -height 30	

entry $a.entry1 -width 5 -textvariable n ;  place $a.entry1 -x 150 -y 20 -width 100 -height 30
entry $a.entry2 -width 5 -textvariable t ;  place $a.entry2 -x 150 -y 70 -width 100 -height 30

button $a.11 -text "CREATE COMPONENT" -command {cre_com $s $n $t} -bg yellow -font {times 10 bold}; place $a.11 -x 70 -y 120 -width 150 -height 40


#set s [hm_info templatetype]      does not recognise optistruct solver

set s [hm_getsolver] 

set i 1
proc cre_com {s n t} {	

	if {$n=="" || $t==""} { tk_messageBox -message "Please enter component name and thickness." -icon info -type ok
	} else { if {$s =="optistruct"} {puts $s;optistruct_sol $n $t
		} elseif {$s =="radioss"} { rad_sol  $n $t
		} else {tk_messageBox -message "Solver not available in the student version." -icon info -type ok}

}
}

proc optistruct_sol {n t} {
	*createmark comps 1 $n
	if {[hm_entityinfo exist comps $n]!=0} {
		tk_messageBox -message "Already exists." -icon info -type ok
		} else {
		*createentity comps cardimage=Part includeid=0 name=$n
		*createmark comps 1 $n 
		set n_id [hm_getmark comps 1]
		*createentity props cardimage=PSHELL includeid=0 name=$n
		*createmark props 2 $n
		set prop_id [hm_getmark props 2]
		*setvalue props id=$prop_id STATUS=1 95=$t
		*setvalue comps id=$n_id propertyid={props $prop_id}
		*createmark comps 1 "all"
		*autocolorwithmark properties 1
		}
}
proc nastran_sol {n t} {
	*createmark comps 1 $n
	if {[hm_entityinfo exist comps $n]!=0} {
		tk_messageBox -message "Already exists." -icon info -type ok
		} else {
		*createentity comps cardimage=Part includeid=0 name=$n
		*createmark comps 1 $n 
		set n_id [hm_getmark comps 1]
		*createentity props cardimage=P1_SHELL includeid=0 name=$n
		*createmark props 2 $n
		set prop_id [hm_getmark props 2]
		*setvalue props id=$prop_id   111=$t
		*setvalue comps id=$n_id propertyid={props $prop_id}
		*createmark comps 1 "all"
		*autocolorwithmark properties 1
		}
}		


proc rad_sol {n t} {
	*createmark comps 1 $n
	if {[hm_entityinfo exist comps $n]!=0} {
		tk_messageBox -message "Already exists." -icon info -type ok
		} else {
		*createentity comps cardimage=Part includeid=0 name=$n
		*createmark comps 1 $n 
		set n_id [hm_getmark comps 1]
		*createentity props cardimage=P1_SHELL includeid=0 name=$n
		*createmark props 2 $n
		set prop_id [hm_getmark props 2]
		*setvalue props id=$prop_id STATUS=1 431=$t
		*setvalue comps id=$n_id propertyid={props $prop_id}
		*createmark comps 1 "all"
		*autocolorwithmark properties 1
		}
}

CONCLUSION:

  • Learned to create component and property cards using tcl/tk.
  • Learned to assign property cards to the components.
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.