# Meshpro

#Source BCL file and check license

#----------------------------------------------------
proc loadMESHPRO {} {
global env va_script_file geom_icons mesh_icons

#Add my icons to the gray group
set mp_geom_icons {
	mp_coarsen 
	mp_trimsurf 
	mp_trmbyplane 
	mp_smoothedge
	mp_extractb
	mp_movefam
	mp_trimcurve
	mp_repairsurf
	mp_dyntrack
	mp_charcurve
	mp_charwinoffset
	mp_mergestl
	mp_convbspfct
	mp_createsec
	mp_meshSizeGlobalBut
	mp_meshSizeSurfBut
	mp_meshSizeCurveBut
	mp_partOptionsBut
	mp_delstuffBut
	mp_adjstlnormBut
}

set mp_mesh_icons {
	mp_smooth
	mp_disdev
	mp_refmesh
	mp_rephole
	mp_adjvect
	mp_smoothone
	mp_outstl
}	

append geom_icons $mp_geom_icons	
append mesh_icons $mp_mesh_icons	
	

#Load up meshprototyper

if [file exists $env(ICEM_ACN)/lib/va/MESH_PRO/src/mesh_pro] {
	set env(AI_MESHPRO) 1
	
	set va_script_file ""
	source "$env(ICEM_ACN)/lib/med_gui/ddn_med.tcl"

	if {[ic_v_init "init prototyper 1"] == "\{Virtual Init Ok\}"}  {
		source "$env(ICEM_ACN)/lib/va/MESH_PRO/src/mesh_pro"
	} else {
		tk_messageBox -message  "License for MeshProtoyper not obtained. . . "
		exit
		#return
	}
	


} else {
	tk_messageBox -message "MeshPrototyper is not installed"
	exit
}

#Set Fast transition for at load
#mszGlobalDEZ build
#mszGlobalDEZ set fastTranFlag 1


}

#Start Various Gui Procedures
#Geometry

#Coarsen Surface  - #1
#---------------------------------------------------------------------

proc onmpCoursenDEZAfterLoad {} {
	set coarsetol .001	 
#	if $auto_pick_mode {geo_coarsen_surface}
	if $auto_pick_mode {mpCoursenDEZPick pick}
	
}
#----------------------------------------------------

proc onmpCoursenDEZOK {} {

	ic_geo_coarsen surfaces $surfList tol $coarsetol  n_iter 4 
    #aie_updateGeoVis
    set surfList ""
}

#--------------------------------------------------------
proc onmpCoursenDEZPickFinish {} {
    # automatic apply when middle mouse button is pressed
    mess "in Finish" 
    if {($surfList != "") && $auto_pick_mode} {
        mpCoursenDEZ apply
        mpCoursenDEZPick pick
    }
}


#Trim Surface  - #2
#---------------------------------------------------------------------
proc onmpTrimSurfDEZLoad {} {
	global mpfam
    set PartList [aie_list_parts 1]
    if {$part_name == ""} {
	set part_name [::AIEnv::GUIManagement::Tree::getSelection part]
        if {$part_name == ""} {set part_name MPJUNK}
    }
	set name [va_auto_name surface ${part_name}.00 $part_name] 
	set entname $name
	set mpfam $part_name


}

#--------------------------------------------------------

proc onMpTrimSurfFamModify {dez val} {
    if {$val == "From screen"} {
	mpTrimSurfDEZ set part_name [geo_select_part_from_screen 1]
    }
}


#--------------------------------------------------------

proc onmpByOnScreenDEZLoad {} {
	global mpfam
	
	if $auto_pick_mode {va_seg_surf_by_screen $part_name}
	aie_create_initial_assemblies
	display_update geo $part_name
}
#--------------------------------------------------------

proc onmpByOnScreenDEZPickOK {} {
	va_seg_surf_by_screen $part_name
	aie_create_initial_assemblies
	display_update geo $part_name
}

#--------------------------------------------------------

proc onmpByOnScreenDEZFinish {} {
     if {($surfList != "") && $auto_pick_mode} {
        mpByOnScreenDEZ apply
        mpByOnScreenDEZ pick
}
}

#--------------------------------------------------------

proc onmpByCurveLoad {} {
	mp_cut_stl_by_curve	{} {} 0 1 0 {} $part_name
	aie_create_initial_assemblies
	display_update geo $part_name
}

#--------------------------------------------------------

proc onmpBySurfEdgeLoad {} {
	mp_cut_stl_by_surf "" "" $part_name
	aie_create_initial_assemblies
	display_update geo $part_name
}
#--------------------------------------------------------
proc onmpByOnSurfLoad {} {
	va_cut_stl $part_name
	aie_create_initial_assemblies
	display_update geo $part_name
}

#--------------------------------------------------------


#Trim by plane  - #3
#---------------------------------------------------------------------
proc onmpTrimbyPlaneDEZLoad {} {
	
	if {![info exists mpTrimPlnNrm] || $mpTrimPlnNrm == ""} {
		set mpTrimPlaneEGVal 0
		set mpTrimPlnNrm "0 1 0"
		set mptrmchoiceVal 0
		set pntnnormal "0 0 0"
	}
}
#--------------------------------------------------------

proc onmpTrimbyPlaneDEZOK {} {
	global va_set
	
	switch $mpTrimPlaneEGVal {
		0 {	
			set va_set(trm_type) pntpln
			set va_set(seg_pt) $pntnnormal 
			set va_set(seg_nm) $mpTrimPlnNrm
		}
		1 {
			set va_set(trm_type) thrpnts
			set va_set(seg_pt) ""
			set va_set(seg_nm) ""
			set va_set(plnpt1) $mpTrmPnt1
			set va_set(plnpt2) $mpTrmPnt2
			set va_set(plnpt3) $mpTrmPnt3
		}
	}
	
	switch $mptrmchoiceVal {
		0 {
			set va_set(seg_surf) vis
		}
		1 {
			set va_set(seg_surf) sel
		}
		2 {
			set va_set(seg_surf) all
		}
	}	


mp_do_seg_surf_pln

}

#--------------------------------------------------------
proc onmpTrimbyPlaneDEZFinish {} {
    # automatic apply when middle mouse button is pressed
    mess "in Finish" 
		
    	#Clear out the plan on apply
        if [info exists va_set(img)] {
     		$tdv_default remove_image $va_set(img) 
 		}    
	
	    switch $mpTrimPlaneEGVal {
			0 {	
				if {($pntnnormal != "") && $auto_pick_mode} {
					set va_set(trm_type) pntpln
					set va_set(seg_pt) $pntnnormal
				 	set va_set(seg_nm) $mpTrimPlnNrm
				}
			}
			1 {
				if {($mptrimpnt1 != "") && $auto_pick_mode} {
        		
        			mpByPlanePickp1 pick
        			mpByPlanePickp2 pick
        			mpByPlanePickp3 pick
    			}		
        	}
		}
	      
    
}
#--------------------------------------------------------
proc onmpByPlanePickp1Finish {} {
        mpByPlanePickp2 pick
        mpByPlanePickp3 pick	
	    
		#mpTrimbyPlaneDEZ apply
	
}
#--------------------------------------------------------

proc onmpByPlanePickPick {} {
	global va_set tdv_default

	
	#set rad 1
	#set vec [mpTrimbyPlaneDEZ get mpTrimPlnNrm]
	#set x_dir    [ic_vcalc vec_norm $vec]
	#set x_dir    [ic_vcalc smult [ic_vcalc nrm $x_dir] $rad]
	#set p1 [ic_vcalc sum $x_dir $pnt]
	#set y_dir    [ic_vcalc product $vec $x_dir]
	#set y_dir    [ic_vcalc smult [ic_vcalc nrm $y_dir] $rad]
	#set p2 [ic_vcalc sum $y_dir $pnt]
	#set p3 [ic_vcalc diff $x_dir $pnt]
	#set p4 [ic_vcalc diff $y_dir $pnt]
	#set va_set(center) [ic_vcalc sum_smult $va_set(bmin) $va_set(bmax) 0.5]

	
	set rad 1	
	set va_set(pln_pnt1) [mpTrimbyPlaneDEZ get mpTrmPnt1] 
	set rr [$tdv_default bbox interesting]
    if {$rr != ""} {
	set va_set(bmin) [lindex $rr 0]
	set va_set(bmax) [lindex $rr 1]
    }
	    
	if ![info exists va_set(img)] {
    	set va_set(img) [pgeom_cut -interesting 0 -color #575]
    	$va_set(img) set_default 2
	} else {
		$tdv_default remove_image $va_set(img)
	}
	
	$va_set(img) configure -display_type 0x3
	$tdv_default add_image $va_set(img)
	$va_set(img) set_material 0.5
	
    set va_set(do_when_create_xyz_start) {
			{set vec [mpTrimbyPlaneDEZ get mpTrimPlnNrm]}
			{set x_dir    [ic_vcalc vec_norm $vec]}
			{set x_dir    [ic_vcalc smult [ic_vcalc nrm $x_dir] $rad]}
			{set p1 [ic_vcalc sum $x_dir $va_set(xyz_xyz)]}
			{set y_dir    [ic_vcalc product $vec $x_dir]}
			{set y_dir    [ic_vcalc smult [ic_vcalc nrm $y_dir] $rad]}
			{set p2 [ic_vcalc sum $y_dir $va_set(xyz_xyz)]}
			{set p3 [ic_vcalc diff $x_dir $va_set(xyz_xyz)]}
			{set p4 [ic_vcalc diff $y_dir $va_set(xyz_xyz)]}
			#{set va_set(center) [ic_vcalc sum_smult $va_set(bmin) $va_set(bmax) 0.5]}
	    	{set va_set(center) [val_center_from_3_pnts $p1 $p2 $p3]}
			{set va_set(normal) [get_plane_normal $p1 $p2 $p3]	}   
    
			#{set va_set(normal) [mpTrimbyPlaneDEZ get pntnnormal]   }
	    	{eval $va_set(img) set_corner $p1 $p2 $p3}
			{eval "$va_set(img) set_ptnorm $va_set(center) $va_set(normal)"}
			{$va_set(img) configure -mbmin $va_set(bmin) -mbmax $va_set(bmax)}

	}	

    set va_set(do_when_create_xyz_continue) {
			{set vec [mpTrimbyPlaneDEZ get mpTrimPlnNrm]}
			{set x_dir    [ic_vcalc vec_norm $vec]}
			{set x_dir    [ic_vcalc smult [ic_vcalc nrm $x_dir] $rad]}
			{set p1 [ic_vcalc sum $x_dir $va_set(xyz_xyz)]}
			{set y_dir    [ic_vcalc product $vec $x_dir]}
			{set y_dir    [ic_vcalc smult [ic_vcalc nrm $y_dir] $rad]}
			{set p2 [ic_vcalc sum $y_dir $va_set(xyz_xyz)]}
			{set p3 [ic_vcalc diff $x_dir $va_set(xyz_xyz)]}
			{set p4 [ic_vcalc diff $y_dir $va_set(xyz_xyz)]}
			#{set va_set(center) [ic_vcalc sum_smult $va_set(bmin) $va_set(bmax) 0.5]}
	    	{set va_set(center) [val_center_from_3_pnts $p1 $p2 $p3]}
			{set va_set(normal) [get_plane_normal $p1 $p2 $p3]	}   
    
			#{set va_set(normal) [mpTrimbyPlaneDEZ get pntnnormal]   }
	    	{eval $va_set(img) set_corner $p1 $p2 $p3}
			{eval "$va_set(img) set_ptnorm $va_set(center) $va_set(normal)"}
			{$va_set(img) configure -mbmin $va_set(bmin) -mbmax $va_set(bmax)}

	}
	set va_set(do_when_create_xyz_end) ""    	
	
}

#--------------------------------------------------------
proc onmpByPlanePickp3Pick {} {
	global va_set tdv_default
	
	set va_set(pln_pnt1) [mpTrimbyPlaneDEZ get mpTrmPnt1] 
	set va_set(pln_pnt2) [mpTrimbyPlaneDEZ get mpTrmPnt2] 
	set va_set(pln_pnt3) [mpTrimbyPlaneDEZ get mpTrmPnt3] 
	


	#set va_set(center) [val_center_from_3_pnts $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(pln_pnt3)]
	#set va_set(normal) [get_plane_normal $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(pln_pnt3)]
	
	set rr [$tdv_default bbox interesting]
    if {$rr != ""} {
	set va_set(bmin) [lindex $rr 0]
	set va_set(bmax) [lindex $rr 1]
    }
	if ![info exists va_set(img)] {
    	set va_set(img) [pgeom_cut -interesting 0 -color #575]
    	$va_set(img) set_default 2
	} else {
		$tdv_default remove_image $va_set(img)
	}

	$va_set(img) configure -display_type 0x3 
	
	$tdv_default add_image $va_set(img)

	#eval $im set_corner $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(pln_pnt3)
	#eval "$im set_ptnorm $center $normal"
	#$im configure -mbmin $bmin -mbmax $bmax
	$va_set(img) set_material 0.5
	#set va_set(im_wp) $im 

		
    set va_set(do_when_create_xyz_start) {
	    	{set va_set(center) [val_center_from_3_pnts $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(xyz_xyz)]}
			{set va_set(normal) [get_plane_normal $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(xyz_xyz)]	}   
	    	{eval $va_set(img) set_corner $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(xyz_xyz)}
			{eval "$va_set(img) set_ptnorm $va_set(center) $va_set(normal)"}
			{$va_set(img) configure -mbmin $va_set(bmin) -mbmax $va_set(bmax)}

	}	

    set va_set(do_when_create_xyz_continue) {
	    	{set va_set(center) [val_center_from_3_pnts $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(xyz_xyz)]}
			{set va_set(normal) [get_plane_normal $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(xyz_xyz)]	}   
	    	{eval $va_set(img) set_corner $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(xyz_xyz)}
			{eval "$va_set(img) set_ptnorm $va_set(center) $va_set(normal)"}
			{$va_set(img) configure -mbmin $va_set(bmin) -mbmax $va_set(bmax)}

	}
			set va_set(do_when_create_xyz_end) {
	    	{eval $va_set(img) set_corner $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(xyz_xyz)}
			{eval "$va_set(img) set_ptnorm $va_set(center) $va_set(normal)"}
			{$va_set(img) configure -mbmin $va_set(bmin) -mbmax $va_set(bmax)}
			
	}
}	
	
#--------------------------------------------------------
proc xonmpByPlanePickp3PickFinish {} {
	global va_set tdv_default
	
	set va_set(pln_pnt1) [lindex [mpTrimbyPlaneDEZ get mpTrmPnt1] 0]
	set va_set(pln_pnt2) [lindex [mpTrimbyPlaneDEZ get mpTrmPnt2] 0]
	set va_set(pln_pnt3) [lindex [mpTrimbyPlaneDEZ get mpTrmPnt3] 0]
	


	set center [val_center_from_3_pnts $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(pln_pnt3)]
	set normal [get_plane_normal $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(pln_pnt3)]
	
	set rr [$tdv_default bbox interesting]
    if {$rr != ""} {
	set bmin [lindex $rr 0]
	set bmax [lindex $rr 1]
    }
	set im [pgeom_cut -interesting 0 -color #575]
	$im configure -display_type 7
		
	$tdv_default add_image $im
	$im set_default 2
	eval $im set_corner $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(pln_pnt3)
	eval "$im set_ptnorm $center $normal"
	$im configure -mbmin $bmin -mbmax $bmax
	$im set_material 0.5
	#set va_set(im_wp) $im 
	
	
	
}
	
#--------------------------------------------------------
proc onmpTrimbyPlaneDEZUnLoad {} {

	if [info exists va_set(img)] {
		$tdv_default remove_image $va_set(img)
	}
}
#--------------------------------------------------------




#Clean Edges  - #4
#---------------------------------------------------------------------
proc onmpSmoothEdgesDEZLoad {} {
	
}

#--------------------------------------------------------

proc onmpSmEdgeLoad {} {
	if $auto_pick_mode {
		mp_smooth_facet_edges_ask
	}
	
}
#--------------------------------------------------------

proc onmpAlToCurveLoad {} {
	mp_smooth_facet_edges_by_curve edge
	
}
#--------------------------------------------------------

proc onmpProjNodeLoad {} {
	mp_smooth_facet_edges_by_curve node
	
}


#--------------------------------------------------------

proc onmpTrimCurveDEZLoad {} {
	set mpmodifyCurveSegFRVal 0
	set mpmodSegmCRVNormEGVal 1
	set SegPlanePntList "0 0 0"
	set seg_angle2 20
	set minSeg2 1
}

proc onmpTrimCurveDEZAfterLoad {} { 
	if $auto_pick_mode {
		mpmodifyCurvSegPick pick

	}
	
}


proc onmpTrimCurveDEZOK {} {
	
	    set crvs ""
	    foreach c $pickCurveSeg {
		if {[ic_geo_check_objects_exist curve $c] == ""} {
		    continue
		} else {
		    lappend crvs $c
		}
	    }
	    if ![llength $crvs] return	
		
	    set fam [ic_geo_get_family curve [lindex $crvs end]]
		set entname [lindex $crvs end]
	
		    switch $mpmodifyCurveSegFRVal {
		0 {
		    #segment by point
		# Procedures modified to use EZCAD function, as requested
		# for multiply points selection. Works in most cases.
		    if ![llength $pickPointSeg] {
				mess "Select points\n" red
			return 
		    }
			va_set_fam_name_etc $fam $entname
			va_segment_curve $pickCurveSeg 0 $pickPointSeg 100
		    set pickCurveSeg ""	
		    set pickPointSeg ""	
		    
		    if $auto_pick_mode {
				mpmodifyCurvSegPick pick
			}	
		    
		    
		    		
		}
		1 {
		    #segment by plane
		    if {$mpmodSegmCRVNormEGVal == 3} {
			if {$segVecList == ""} {mess "Warning:Point is not defined!" red;return}
			set SegPlanePList [lindex $segVecList 0]
		    } else {
			if {$SegPlanePntList == ""} {mess "Warning:Point is not defined!" red;return}
			set SegPlanePList [lindex $SegPlanePntList 0]
		    }
		    
		    if {[llength $SegPlanePList]==1} {
			set plane_pnt [ic_geo_get_point_location $SegPlanePList]
		    } else {
			set plane_pnt $SegPlanePList
		    }                      
		    mess "segment by the point: $plane_pnt\n" blue
		    #mess "  SegPlanePntList $SegPlanePntList    segVecList $segVecList  SegPlanePList $SegPlanePList \n"             
		    switch $mpmodSegmCRVNormEGVal {
			0 {set plane_n [list 1 0 0]}
			1 {set plane_n [list 0 1 0]}
			2 {set plane_n [list 0 0 1]}
			3 {set plane_n [ic_vcalc vec_norm [lindex $segVecList 0]] }
		    }   
		    #mess "plane_p $plane_pnt plane_n $plane_n\n" blue
		    set seg_crvs ""
			busy 1
		    foreach c $crvs {
			switch [ic_geo_get_object_type curve $c] {
			    mesh {
				ic_geo_create_curve_segment $c plane plane_p $plane_pnt plane_n $plane_n keep_old 0    
				lappend seg_crvs $c
			    }
			    default {
				mess "Only works for faceted data currently.\n"
			    }
			}
		    }  
			busy 0
		    if {$seg_crvs != ""} {mess "segmented $seg_crvs\n"}   
		              
		}
		2 {
		    #segment by connectivity
			busy 1
		    foreach c $crvs {
			set type [ic_geo_get_object_type curve $c]
			if {$type == "param"} {
			    mess "This function is only valid for faceted curves. Skipping $c\n" red
			    continue
			}
			ic_geo_create_curve_segment $c connect keep_old $keepOriginCurvFlag
		    }
			busy 0
		}
		
		3 {
		    #segment by angle
			busy 1
		    foreach c $crvs {
			set type [ic_geo_get_object_type curve $c]
			if {$type == "param"} {
			    mess "This function is only valid for faceted curves. Skipping $c\n" red
			    continue
			}
			ic_geo_create_curve_segment $c angle angle $seg_angle2 minedge $minSeg2 keep_old $keepOriginCurvFlag
		    }
			busy 0
		}
	    }

	
}


proc onmpmodifyCurvSegPickFinish {} {

	if {$pickCurveSeg != "" && $auto_pick_mode} {
		mpmodifyCurvPntPick pick
		mpTrimCurveDEZ apply
	}	

}




#--------------------------------------------------------

proc onmpExtractBoundDEZLoad {} {

    set pickList ""
    set pickSurf ""

    if {![info exists fangle] || $fangle == "" } {
	    set fangle 20
	}   

    set PartList [aie_list_parts 1]
    set BList [list Interior Exterior Both]
    set boundary Both
    if {$MinSeg == ""} {set MinSeg 0}
    
    
    if {$part_name == ""} {
	set part_name [::AIEnv::GUIManagement::Tree::getSelection part]
        if {$part_name == ""} {set part_name CURVES}
    }
	set name [va_auto_name curve ${part_name}.00 $part_name] 
	set entname $name

	
    
}

proc onMpextCurvesFamModify {dez val} {
    if {$val == "From screen"} {
	mpExtractBoundDEZ set part_name [geo_select_part_from_screen 1]
    }
}




#--------------------------------------------------------

proc onmpExtractBoundDEZAfterLoad {} {

    if $auto_pick_mode {
	     mpExtractBoundDEZ apply
	     mpextBoundCurvesPick pick
    }	

}

#--------------------------------------------------------

proc onmpExtractBoundDEZOK {} {
 
	global geom_visible   
    set fam [aie_new_part $part_name]
	set name [va_auto_name curve [mpExtractBoundDEZ get name] $fam] 
	set entname $name    
    if { [ic_geo_is_loaded] == 0 } {
	ic_empty_tetin
    }
    set geom_visible(curve) 1	
	
	
	    if {$pickCurveExtract == ""} return
	    set param_surfs ""
	    set mesh_surfs ""
	    foreach i $pickCurveExtract {
		set type [ ic_geo_get_object_type surface $i]
		if { $type == "mesh" } {
		    lappend mesh_surfs $i
		} elseif { $type == "param" } {
		    lappend param_surfs $i
		} else {
		    mess "unhandled surface type $type, skipping\n"
		}
	    }
	    
	    set new_crvs ""
	    if { $mesh_surfs != "" } {
		switch $boundary {
		    Both {set bb 2}
		    Interior {set bb 0}
		    Exterior {set bb 1}
		    default {set bb 2}
		}
		foreach obj $mesh_surfs {
		    set new [ic_geo_extract_curves $obj $bb $fangle $MinSeg]
		    set new_crvs [concat $new_crvs $new]
		}
	    }
	    if { $param_surfs != "" } {
		set new_crvs [ic_geo_create_surface_edges $param_surfs]		
	    }
	    set pickCurveExtract ""
	    
	    
		ic_geo_set_family curve $part_name names $new_crvs
	    
	    if $segFlag {
		    foreach crv $new_crvs {
		    	ic_geo_create_curve_segment $crv connect keep_old 0
	    	}
    	}
	    
	    aie_updateGeoVis
	    
	    
	    
}
	

proc onmpcreateBoundCurvesPickFinish {} {
     if {($pickCurveExtract != "") && $auto_pick_mode} {
	     mpExtractBoundDEZ apply
	     mpcreateBoundCurvesPick pick
     }
}


#--------------------------------------------------------

proc onmpMoveFamilyDEZLoad {} {
    global current_part_to_load tdv_default
    
    if [info exists current_part_to_load(name)] {
	set name $current_part_to_load(name)
    } else {
	set name [ic_geo_get_unused_part PART]
    }
    set entityList ""
    set PartList [aie_list_parts 1]
    if {$part_name == ""} {
    	set part_name [::AIEnv::GUIManagement::Tree::getSelection part]
    		if {$part_name == ""} {set part_name PART.1}
	}
    foreach st {geo mesh} {
	set select_${st}_0d 0
	foreach sd {1 2 3} {
	    set select_${st}_${sd}d 1
	}
    }
    
    set bb [$tdv_default bbox interesting]
    if {$bb != ""} {
	foreach c $bb m {min max} {
	    foreach v $c x {x y z} {
		set $m$x [format %g $v]
	    }
	}
    }
    geo_select_either_set_prefix ::AIEnv::DEZ::createPartDEZ::select_
    set AllowActiveReload 1
}

proc onmpMoveFamilyDEZApply {} {

    if {$part_name == ""} { set part_name [ic_geo_get_unused_part PART] }
    set part_name [ic_geo_valid_name $part_name 1]
    
    set dims ""
    set single_type ""
    foreach d {0 1 2 3} {
	if [set select_geo_${d}d] {
	    if {$dims == ""} {
		set single_type [lindex {point curve surface body} $d]
	    } else {
		set single_type ""
	    }
	    lappend dims $d
	}
    }
    
    set uns ""
    if [info exists mpcreatePartSelectVal] {
	if {$part_name == "VORFN" && $mpcreatePartSelectVal != 3} {
	    msg ERROR "Part: VORFN can contain only block entities"
	    return
	}
	switch $mpcreatePartSelectVal {
	    0 { }
	    1 {
		geo_modify_moveseg surface triangle 1 $part_name
	    }
	    2 {
		set uns [ic_uns_create_selection_subset 0]
		set p1 "$minx $miny $minz"
		set p2 "$maxx $maxy $maxz"
		ic_uns_subset_add_region $uns $p1 $p2 $BoxFlag $dims
		set entityList "unsmap $uns"
	    }
	    3 {
		aie_change_part_blocks $blocks $part_name
		return
	    }
	}
    }
    if {$entityList == ""} {
	mess "No entities selected\n" red
	return
    }
    if {([lindex $entityList 0] != "unsmap") && ($single_type != "") && ([lindex $entityList 0] != $single_type)} {
	set entityList [list $single_type $entityList]
    }
    catch {unset change_objs}

    foreach {type objs} $entityList {
	if {$type == "unsmap"} {
		ic_uns_set_part $objs $part_name
	} else {
	    eval lappend change_objs($type) $objs
	}
    }
    foreach type [array names change_objs] {
	ic_geo_set_part $type $change_objs($type) $part_name
    }
    ::AIEnv::GUIManagement::Tree::AddGroup part $part_name
    ::AIEnv::GUIManagement::Tree::ToggleGroupVisibility part $part_name same
    
    if {$uns != ""} { ic_uns_subset_delete $uns}
    set entityList ""
}


proc onmpcreatePartSelLoad {} {
    global auto_pick_mode
    if $auto_pick_mode { 
	mpcreatePartPick pick
    }
}

proc onmpcreatePartPickFinish {} {
    global auto_pick_mode
    if {$auto_pick_mode && $entityList != ""} {
	mpMoveFamilyDEZ apply
	mpcreatePartPick pick
    }
}

proc onmpcreatePartSelFacLoad {} {
    global auto_pick_mode
    if {$auto_pick_mode} {
	    mpMoveFamilyDEZ apply
    }
}

proc onmpcreatePartSelFacFinish {} {
	global auto_pick_mode
    if {$auto_pick_mode } {
	    mpMoveFamilyDEZ apply
    }
}	


proc onMpcreatePartNameModify {dez val} {
    if {$val == "From screen"} {
	mpMoveFamilyDEZ set part_name [geo_select_part_from_screen 1]
    }
}

#--------------------------------------------------------

proc onmpRepDropSurfLoad {} {
	if $auto_pick_mode {
	va_close_hole
	aie_create_initial_assemblies
	}
}

proc onmpRepFillSurfLoad {} {
	
	mp_repair_holes
	aie_create_initial_assemblies
	
}


#--------------------------------------------------------

proc onmpDynamicTrkDEZLoad {} {
	
	global va_set
	set PartList [aie_list_parts 1]
    if {$part_name == ""} {
	set part_name [::AIEnv::GUIManagement::Tree::getSelection part]
    if {$part_name == ""} {set part_name MPCURV}
    }
	set name [va_auto_name surface ${part_name}.00 $part_name] 
	set entname $name	
	
}	
	
proc onmpDynamicTrkDEZAfterLoad {} {
	
	if $auto_pick_mode {
		mpDynTrkPick pick
		mpDynamicTrkDEZ apply
	}
}


proc mp_move_point {} {
	#mess "Moving point"
	#::va_select_move
	vid_set_modified [geo_select point]
	vid_move_spec
}

proc vid_move_spec {} {
# To stop Continious mode -> Cancel selection 
    global va_set 
	set select_action done
	set va_set(do_modify) 1
	set va_set(do_when_create_xyz) 1
	set va_set(do_when_create_xyz_start) vid_do_modify
	set va_set(do_when_create_xyz_continue) vid_do_modify
	set va_set(do_when_create_xyz_end) vid_do_modify
#Set default settings
		ic_curve - - - - rebuild 2 cre_pnts 0
		ic_surface - - - - rebuild 2 btopo 0
banner "Move"
va_undo_group_begin
	set va_set(confirm) 0
#vam_wait_for_click
	va_create_xyz auto 1 
	vid_move_end 
}




#--------------------------------------------------------

proc onmpCharCurveDEZLoad {} {
	va_hard_corner
	display_update geo MPJUNK
	display_update geo MPCHAR
	display_update geo MPMPTPTS
	display_update geo MPTEMP
	aie_create_initial_assemblies
}

proc onmpCharCurveDEZUnLoad {} {

	if [winfo exists .va_slice] {
		destroy .va_slice
	}

}

proc onmpCharWinOffsetDEZLoad {} {
	va_offset_win
	display_update geo MPJUNK
	display_update geo MPCHAR
	display_update geo MPMPTPTS
	display_update geo MPTEMP	
	aie_create_initial_assemblies
	
	
}

proc onmpCharWinOffsetDEZUnLoad {} { 

	if [winfo exists .offset_win] {
		destroy .va_slice
	}

}

#--------------------------------------------------------

proc onmpCreateSectionDEZLoad {} {
	global tdv_default
	
    set PartList [aie_list_parts 1]
    if {$part_name == ""} {
	set part_name [::AIEnv::GUIManagement::Tree::getSelection part]
        if {$part_name == ""} {set part_name MPSECT}
    }
	set name [va_auto_name surface ${part_name}.00 $part_name] 
	set entname $name	
	
	set mpSectPlaneEGVal 0
	if {![info exists normal] || $normal == "" } {

	set normal "0 1 0"
	set screennormal 1
	set numsect 5
	
	set mpSectPlaneXYZEGVal 0
	set mpsectDeltaVal 0
	set mpsectdelta 0
	set mpSectSelEGVal 1
	set mpsectcrbspchkVal 1
	set mpsectrapproxchkVal 0
	set mpsectgritemVal 1
	set mpsecttol .1
	set mpsectang 10
	
	set mpsectstart "0 0 0"
	#set mpsectend "0 0 0"
	if { ![info exists mpsectend] || $mpsectend == ""} {
		set mpsectendx [lindex [lindex [$tdv_default bbox interesting] 1] 0]
		set mpsectendy [lindex [lindex [$tdv_default bbox interesting] 0] 1]
		set mpsectendz [lindex [lindex [$tdv_default bbox interesting] 1] 2]
		set mpsectend [list $mpsectendx $mpsectendy $mpsectendz]
	}
	set mpsectpnt3Val 1
	set mpsectscnrmlVal 1
	set mpSectpnt3Flag 1
	
	::AIEnv::GUIManagement::ToggleGrey mpsectscnrml
	::AIEnv::GUIManagement::ToggleGrey mpsectcrbspchk
	
	}
	
	
	
}


proc onmpCreateSectionDEZAfterLoad {} {

	if {![info exists mpsectDeltaVal] || $mpsectDeltaVal == "" } {
		set mpsectDeltaVal 0
		set mpsectdelta 0
	}
}


proc onmpCreateSectionDEZOK {} {
	#Adding All the variables necessary from the old gui.   
	#Due to time constraints
	global va_set
	
	switch $mpSectPlaneEGVal {
		0 {set va_set(sec)  pln}
		1 {set va_set(sec)  3pt}
		2 {set va_set(sec)  crv}
		3 {set va_set(sec)  crv_exists}
	}
	switch $mpSectPlaneXYZEGVal {
		0 {set va_set(sec_p) X}
		1 {set va_set(sec_p) Y}
		2 {set va_set(sec_p) Z}
	}	
	
	set va_set(nor2scr) !$mpsectscnrmlVal
	set va_set(sec_pt1)  $mptrimpnt1 
	set va_set(sec_pt2)  $mptrimpnt2 
	set va_set(sec_pt3)  $mptrimpnt3 
	set va_set(sec_no)   $numsect
	set va_set(sec_step) $mpsectdelta
	set va_set(picpnts) $piccrvpnts

	if {[llength $mpsectstart] == 1 } {
		set va_set(sec_sta)  [lindex $mpsectstart 0]
	} else {
		set va_set(sec_sta)  $mpsectstart
	}
	if {[llength $mpsectend] == 1} {
		set va_set(sec_end)  [lindex $mpsectend 0]
	} else {
		set va_set(sec_end)  $mpsectend
	}
	set va_set(sec_fam)  $part_name
	switch $mpSectSelEGVal {
		0 {set va_set(sec_all) "all"}
		1 {set va_set(sec_all) "visible"} 
	}
	set va_set(bsp_tol)  0
	set va_set(crv_typ)  $mpsectcrbspchkVal
	set va_set(crv_typ_rep)  $mpsectrapproxchkVal
	set va_set(crv_typ_rep_tol)  $mpsecttol
	set va_set(crv_typ_rep_angle)  $mpsectang
	set va_set(exists) $pickcrvexist
	
		
	tdv_active 0
	catch {va_do_section}
	tdv_active 1
	busy reset
	aie_create_initial_assemblies
	
}	


proc onMpCreateSectionFamModify {dez val} {
    if {$val == "From screen"} {
	mpCreateSectionDEZ set part_name [geo_select_part_from_screen 1]
    }
}	


proc onmpsectplanepntp1PickFinish {} {
	if {[info exists mptrimpnt2] && $mptrimpnt2 == "" } {
		mpsectplanepntp2Pick pick
		if { [info exists mpsectscnrmlVal] && $mpsectscnrmlVal} {
			mpsectplanepntp3Pick pick
		}
	}

}




proc onmpsectplanepntp3PickPick {} {
	global va_set tdv_default
	
	set va_set(pln_pnt1) [mpCreateSectionDEZ get mptrimpnt1] 
	set va_set(pln_pnt2) [mpCreateSectionDEZ get mptrimpnt2] 
	set va_set(pln_pnt3) [mpCreateSectionDEZ get mptrimpnt3] 
		
	set rr [$tdv_default bbox interesting]
    if {$rr != ""} {
	set va_set(bmin) [lindex $rr 0]
	set va_set(bmax) [lindex $rr 1]
    }
	if ![info exists va_set(img)] {
    	set va_set(img) [pgeom_cut -interesting 0 -color #575]
    	$va_set(img) set_default 2
	} else {
		$tdv_default remove_image $va_set(img)
	}

	$va_set(img) configure -display_type 0x3 
	$tdv_default add_image $va_set(img)
	$va_set(img) set_material 0.5
	
    set va_set(do_when_create_xyz_start) {
	    	{eval $va_set(img) set_corner $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(xyz_xyz)}
			{eval "$va_set(img) set_ptnorm $va_set(center) $va_set(normal)"}
			{$va_set(img) configure -mbmin $va_set(bmin) -mbmax $va_set(bmax)}

	}	

    set va_set(do_when_create_xyz_continue) {
	    	{set va_set(center) [val_center_from_3_pnts $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(xyz_xyz)]}
			{set va_set(normal) [get_plane_normal $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(xyz_xyz)]	}   
	    	{eval $va_set(img) set_corner $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(xyz_xyz)}
			{eval "$va_set(img) set_ptnorm $va_set(center) $va_set(normal)"}
			{$va_set(img) configure -mbmin $va_set(bmin) -mbmax $va_set(bmax)}

	}
			set va_set(do_when_create_xyz_end) {
	    	{eval $va_set(img) set_corner $va_set(pln_pnt1) $va_set(pln_pnt2) $va_set(xyz_xyz)}
			{eval "$va_set(img) set_ptnorm $va_set(center) $va_set(normal)"}
			{$va_set(img) configure -mbmin $va_set(bmin) -mbmax $va_set(bmax)}
			
	}	    	
	
}	
	

proc onmpCreateSectionDEZUnLoad {} {

	if [info exists va_set(img)] {
		$tdv_default remove_image $va_set(img)
	}
}



#--------------------------------------------------------



proc onmpDeletePntsLoad {} {
	if $auto_pick_mode {
		set points [geo_select point]
		ic_delete_geometry point names $points
	}
}

proc onmpDeleteCrvLoad {} {
		set curves [geo_select curve]
		ic_delete_geometry curve names $curves
}

proc onmpDeleteSurfLoad {} {
	set surfs [geo_select surface]
	ic_delete_geometry surface names $surfs
}

proc onmpDeleteEntLoad {} {
	set entities [geo_select entity]
	busy 1
	tdv_active 0
	foreach ent $entities {
		ic_delete_geometry [lindex $ent 0] names [lindex $ent 1] 
	}
	tdv_active 1
	busy reset
}

proc onmpDeleteFacLoad {} {
	if $auto_pick_mode {
	geo_modify_object_delete surface triangle
	}
}

proc onmpDeleteSegLoad {} {
	geo_modify_object_delete curve segment
}

#--------------------------------------------------------

proc onmpAdjStlNormDezLoad {} {
	
	aie_facets_to_mesh
	foreach surf [ic_geo_get_objects surface] {
		set meshsurf [ic_geo_get_object_type surface $surf]
		if {$meshsurf == "mesh"} {
			ic_delete_geometry surface names $surf
		}
	}
	
	reorientMeshDEZ build
	reorientMeshDEZ show

	
#	aie_mesh_to_facets
#	ic_unload_unstruct

}


#--------------------------------------------------------

proc onmpGlbMeshParamDEZLoad {} {
	global setglbflag
	
	#set flag so that this is only set the first time
	if { ![info exists setglbflag] || $setglbflag != 1} {
		ic_set_meshing_params global 0 gfast 1
		set setglbflag 1
	}

	mszGlobalDEZ build
	#mszGlobalDEZ set fastTranFlag 1
	#mszGlobalDEZ set tritol 11
	mszGlobalDEZ show	
		
	
}

#--------------------------------------------------------

#------------------------------------------------------------------------------------------

proc onmpCrMeshDEZLoad {} {

if {[info exists env(MESHPRO_FULL)] && $env(MESHPRO_FULL)} {	
    meshTetDEZ build
    meshTetDEZ set use_surf 0
	 meshTetDEZ set surfMeshFlag 1
	 meshTetDEZ show
}

#Turn on Smoothing
set mpsmthFlag 1
::AIEnv::GUIManagement::ToggleGrey mpCrMeshSmthChk

#Turn on Batch proccess
set batchFlag 1
::AIEnv::GUIManagement::ToggleGrey mpbProc

set mpRnMshFamFlag 1	 
set numSmooth 5
set smoothAR 0.4

}




proc onmpCrMeshDEZOK {} {
global file_name tdv_default options aie_meshDisplay is_win fam_visible

	
#	qualityMetricsDEZ build
#	set meshTetMethodEGVal 0
#	meshTetDEZ apply

	ic_unload_mesh
	fam_delete_unused
	
	if {[ic_geo_is_modified] && ($batchFlag)} {
		#aie_saveProject 1
		if [info exists file_name(tetin)] {
			ic_save_tetin $file_name(tetin)
		} else {
			aie_saveProject 1
		}
	}	

	if $mpCrMeshVisFlag {ic_save_tetin temp_tetin.tin 1}	
		
	if $batchFlag {
		if $mpRnMshFamFlag {
		set fams [array names fam_visible]
		foreach fam $fams {
			if {$fam != "ORFN"} {
				if !$mpCrMeshVisFlag {
					lappend famlist $fam
					ic_geo_rename_family $fam $fam.1
				} else {
					if $fam_visible(${fam})  {
						lappend famlist $fam
						ic_geo_rename_family $fam $fam.1
					}
				}
			}
		}
		}
	}

	aie_delete_empty_parts
	aie_autosizing tetra
	if !$batchFlag {set loadFlag 1}	

	if {$file_name(tetin) == "" } {
		set batchFlag 1
		set tetfile [med_file_select tetin 0]
	} else {
		set tetfile  $file_name(tetin)
	}
	if {$file_name(tetin) == "" } {return}
	set meshFN [file join $file_name(domains_dir) tetra_mesh.uns]
	set trunc_uns [win_shortname [file dirname $meshFN]]/[file tail $meshFN]
	if [file exists $meshFN] {cmd_rm $meshFN}
	set useMeshParts ""

	
		
	if !$batchFlag {
		ic_run_tetra tin uns run_cutter 1 fix_holes 1 write_volume 0 in_process 1 log tetra_cmd0.log


	} else {
		if $mpCrMeshVisFlag {
			ic_run_tetra temp_tetin.tin $trunc_uns run_cutter 1 fix_holes 1 write_volume 0 in_process 0 log tetra_cmd0.log
			
			
			} else {
			ic_run_tetra $tetfile $trunc_uns run_cutter 1 fix_holes 1 write_volume 0 in_process 0 log tetra_cmd0.log
		}
		

	}		

	if {[info exists famlist] && [llength $famlist] > 0} {
		foreach fam $famlist {
			set orig_name [file rootname $fam]
			ic_geo_rename_family $fam $orig_name
		}	
	}	
	

	if $batchFlag {
		if {![file exists $meshFN]} { return }
		ic_load_unstruct $meshFN
	}	
	

	
	
	if $mpsmthFlag {
		mess "smoothing surface mesh...\n" blue
		ic_smooth_elements map all upto $smoothAR iterations $numSmooth \
		fix_families $useMeshParts smooth TRI_3 float TETRA_4 laplace 1
	}					
	


	
	
	aie_updateMeshVis
	aie_updateGeoVis
	aie_initial_unsmesh_visibility
	aie_afterStuffLoaded
	aie_update_icons mesh	
	aie_create_initial_assemblies
	
				
}


#--------------------------------------------------------

proc onmpSmoothDEZLoad {} {
	
	smoothDEZ build
	smoothDEZ set laplaceFlag 1
	
	smoothDEZ show
	
}

#--------------------------------------------------------

proc onmpMeshQualDEZLoad {} {
	
	qualityMetricsDEZ build
	qualityMetricsDEZ set qualdiag 16
	qualityMetricsDEZ set checkElems visible
	
	qualityMetricsDEZ show
	
}

#--------------------------------------------------------

proc onmpRefineDEZLoad {} {

	adjustMeshDEZ build
	adjustMeshDEZ set adjustMeshTypeGGVal  1
	adjustMeshDEZ set RefineMethod 1
	adjustMeshDEZ set refinemaxDev 0.5
	adjustMeshDEZ set refSteps 3
	
	adjustMeshDEZ show
		
}

#--------------------------------------------------------

proc onmpRotateViewDEZLoad {} {
	
	set rotangle 90
	set mpRotateViewVecEGVal 0
}


proc onmpRotateViewDEZOK {} {
	
	global tdv_default
	switch $mpRotateViewVecEGVal {
		0 { 
			set vector "1 0 0"
		}
		1 { 
			set vector "0 1 0"
		}
		2 { 
			set vector "0 0 1"
		}
	}
	
	set angle [expr ($rotangle * 3.14159) / 180]
	
	eval tdv_rotate_axis $tdv_current_viewer $vector $angle
	tdv_trans_update $tdv_current_viewer
		
}




#--------------------------------------------------------

proc mp_view {type} {
    global tdv_current_viewer histogram_args plot_window

    switch $type {
	fitWindow {tdv_scale_to_fit $tdv_current_viewer}
	boxZoom   {tdv_zoomin $tdv_current_viewer}
        fitBox    {tdv_zoomout $tdv_current_viewer}
	rotate    {
	    tdv_rotate_axis $tdv_current_viewer 0 1 0 1.57075
                                      # pi/2 about the Y axis
	    tdv_trans_update $tdv_current_viewer
	}
	top       {
		tdv_along_axis $tdv_current_viewer -z
		tdv_scale_to_fit $tdv_current_viewer
	}
	bottom    {
		tdv_along_axis $tdv_current_viewer +z
		tdv_rotate_axis $tdv_current_viewer 0 0 1 3.14159
		tdv_trans_update $tdv_current_viewer
		tdv_scale_to_fit $tdv_current_viewer
	}
	right     {
		tdv_along_axis $tdv_current_viewer -y
		tdv_scale_to_fit $tdv_current_viewer
	}
	left      {
		tdv_along_axis $tdv_current_viewer +y
		tdv_scale_to_fit $tdv_current_viewer
	}
	front     {
		tdv_along_axis $tdv_current_viewer +x
		tdv_rotate_axis $tdv_current_viewer 0 0 1 -1.57075
		tdv_trans_update $tdv_current_viewer
		tdv_scale_to_fit $tdv_current_viewer
	}
	back      {
		tdv_along_axis $tdv_current_viewer -x
		tdv_rotate_axis $tdv_current_viewer 0 0 1 1.57075
		tdv_trans_update $tdv_current_viewer
		tdv_scale_to_fit $tdv_current_viewer
	}
	iso       {
		tdv_isoview $tdv_current_viewer
		tdv_scale_to_fit $tdv_current_viewer
	}
	edit      {
	    if [info exists histogram_args] {unset histogram_args}
	    savedview_edit $tdv_current_viewer $plot_window}
    }
}
# -------------------------------------------------
proc onmpcreateElemsDEZLoad {} {
	
	createElemsDEZ build
	createElemsDEZ set createElemsRGVal 2
	createElemsDEZ show
}
# -------------------------------------------------

proc onmpOffsetMeshDEZLoad {} {
    
	set PartList [aie_list_parts 1]
    if {$part_name == ""} {
	set part_name [::AIEnv::GUIManagement::Tree::getSelection part]
        if {$part_name == ""} {set part_name MPOFF}
    }
    if {$side_part == ""} {
	set side_part [::AIEnv::GUIManagement::Tree::getSelection part]
        if {$side_part == ""} {set side_part MPOFFS}
    }
	set sideflag 0
	set distance 10
}


proc onmpOffsetMeshDEZOK {} {
global off_set
    
	set off_set(dis) $distance
	set off_set(nfam) $part_name
	set off_set(nfamsides) $sideflag
	set off_set(nfamside) $side_part

	mp_offset_mesh $distance $part_name $sideflag $side_part
    
	aie_create_initial_assemblies
   
}	 


proc onMpOffsetPartModify {dez val} {
    if {$val == "From screen"} {
	mpOffsetMeshDEZ set part_name [geo_select_part_from_screen 1]
    }
}	


proc onMpOffsetPartSideModify {dez val} {
    if {$val == "From screen"} {
	mpOffsetMeshDEZ set side_part [geo_select_part_from_screen 1]
    }
}	

# -------------------------------------------------

proc onmpDynamicTrkDEZOK {} {
	global va_set
	
	ic_delete_geometry curve names $va_set(name) 0
	#set coords [va_check_data_set_points $pointlist]
	set entname [mpDynamicTrkDEZ get name]
#	set newlist [va_check_data_set_points $pointlist point $part_name $entname]
	set ppntlist ""
	foreach pnt $pointlist  {
		set pntname [va_auto_name point $entname $part_name]
		ic_geo_cre_pnt $part_name $pntname $pnt
		set cmd "ic_vdefine $pntname vector {} [list $pnt] "
		eval $cmd
		lappend ppntlist $pntname
	}
		
	
	if {[llength $coords] < 2} return
	#if [catch {ic_geo_cre_bsp_crv_n_pnts $va_set(fam) $va_set(name) $newlist } crvnpnt] {	
		#mess "Error: $crvpnt"
	#	busy reset
	#	return
	#} else {	
	#	if { ![info exists crvnpnt] || $crvnpnt == "" } {return}
	#	set spl_ncp [ic_geo_crv_data $crvnpnt ncp]
	#	set spl_order [ic_geo_crv_data $crvnpnt order]
	#	set nnames $crvnpnt
	#	va_v_entity_define $crvnpnt curve points $newlist	
	#}
		
	set crvname [::va_auto_name curve C_$entname $part_name]
	ic_vdefine $crvname curve default $ppntlist
	ic_vcreate $crvname
	ic_geo_set_family curve $part_name names $crvname
	
	aie_create_initial_assemblies
	
}

proc onmpDynTrkPickPick {} {
	
    global va_set coords
    set fam [mpDynamicTrkDEZ get part_name]
	set entname [mpDynamicTrkDEZ get name]
	set va_set(name) [va_auto_name curve $entname $fam]
	set pointlist ""
	set va_set(dyn_pnt) ""
	mpDynamicTrkDEZ set name $va_set(name)
    #	set va_set(do_when_create_xyz) 1
    set va_set(unset_list) do_when_create_xyz
    set va_set(fam) $fam
    set va_set(do_when_create_xyz_start) {
	{ic_delete_geometry curve names $va_set(name) 0}
	{set va_set(dyn_pnt) $coords}
	{if {[llength $coords] > 0} {
		if {$va_set(xyz_xyz) != ""} {
		lappend va_set(dyn_pnt) $va_set(xyz_xyz)
		}
		ic_geo_cre_bsp_crv_n_pnts $va_set(fam) $va_set(name) $va_set(dyn_pnt)
		ic_highlight names $va_set(name) width 3 color white}    
    }
    }			    
    set va_set(do_when_create_xyz_continue) {
	{ic_delete_geometry curve names $va_set(name) 0}
	{set va_set(dyn_pnt) $coords}
	{if {[llength $coords] > 0} {
		if {$va_set(xyz_xyz) != ""} {
		lappend va_set(dyn_pnt) $va_set(xyz_xyz)
		}
		
		ic_geo_cre_bsp_crv_n_pnts $va_set(fam) $va_set(name) $va_set(dyn_pnt)
		ic_highlight names $va_set(name) width 3 color white}    
    }
    }		
    set va_set(do_when_create_xyz_end) {
	{ic_delete_geometry curve names $va_set(name) 0}
	{set va_set(dyn_pnt) $coords}	
	{if {[llength $coords] > 0} {
		if {$va_set(xyz_xyz) != ""} {
		#lappend va_set(dyn_pnt) $va_set(xyz_xyz)
		}

		ic_geo_cre_bsp_crv_n_pnts $va_set(fam) $va_set(name) $va_set(dyn_pnt)
		ic_highlight names $va_set(name) width 3 color white}
	
    }
    }
	
	aie_create_initial_assemblies
	
}


proc onmpDynTrkPickFinish {} {
	mpDynamicTrkDEZ apply
	
}



# -------------------------------------------------

global ddn_part_selected_sheetnumber
set ddn_part_selected_sheetnumber 1
#mszGlobalDEZ build
#loadMESHPRO

