• Abaqus (0)
  • Questions (1)
Ask a Question

Recent Posts

  • Thay thế New Line từ Clipboard với batch file (Window)
  • Macro Hypermesh tạo comp đối xứng, Tạo comps mới full thuộc tính như comps ban đầu
  • JSON vs VBA

Recent Comments

  • admin on Protected: chatchit
  • admin on Protected: chatchit
  • tt on Protected: chatchit
  • tt on Protected: chatchit
  • admin on Protected: chatchit
Tí Tẹo
  • Home
  • Community
  • Documents
  • CAE
    • Vật Liệu
    • Toán
  • Skill
  • Giải Trí
No Result
View All Result
  • Login
  • Register

Notifications

  • JSON vs VBA
    5 months
  • JSON vs VBA
    5 months
  • Thay thế New Line từ Clipboard với batch file (Window)
    5 months
  • Thay thế New Line từ Clipboard với batch file (Window)
    5 months
  • JSON vs VBA
    9 months
  • Macro Hypermesh tạo comp đối xứng, Tạo comps mới full thuộc tính như comps ban đầu
    9 months
  • Thay thế New Line từ Clipboard với batch file (Window)
    10 months
  • Thay thế New Line từ Clipboard với batch file (Window)
    10 months
  • JSON vs VBA
    12 months
  • JSON vs VBA
    12 months
  • Thay thế New Line từ Clipboard với batch file (Window)
    1 year
  • Thay thế New Line từ Clipboard với batch file (Window)
    1 year
  • JSON vs VBA
    1 year
  • JSON vs VBA
    1 year
  • Thay thế New Line từ Clipboard với batch file (Window)
    1 year
  • Thay thế New Line từ Clipboard với batch file (Window)
    1 year
  • Thay thế New Line từ Clipboard với batch file (Window)
    1 year
  • Thay thế New Line từ Clipboard với batch file (Window)
    1 year
  • Macro Hypermesh tạo comp đối xứng, Tạo comps mới full thuộc tính như comps ban đầu
    1 year
  • Macro Hypermesh tạo comp đối xứng, Tạo comps mới full thuộc tính như comps ban đầu
    1 year
  • Show older
Tí Tẹo
  • Home
  • Community
  • Documents
  • CAE
    • Vật Liệu
    • Toán
  • Skill
  • Giải Trí
No Result
View All Result
  • Login
  • Register

Notifications

  • JSON vs VBA
    5 months
  • JSON vs VBA
    5 months
  • Thay thế New Line từ Clipboard với batch file (Window)
    5 months
  • Thay thế New Line từ Clipboard với batch file (Window)
    5 months
  • JSON vs VBA
    9 months
  • Macro Hypermesh tạo comp đối xứng, Tạo comps mới full thuộc tính như comps ban đầu
    9 months
  • Thay thế New Line từ Clipboard với batch file (Window)
    10 months
  • Thay thế New Line từ Clipboard với batch file (Window)
    10 months
  • JSON vs VBA
    12 months
  • JSON vs VBA
    12 months
  • Thay thế New Line từ Clipboard với batch file (Window)
    1 year
  • Thay thế New Line từ Clipboard với batch file (Window)
    1 year
  • JSON vs VBA
    1 year
  • JSON vs VBA
    1 year
  • Thay thế New Line từ Clipboard với batch file (Window)
    1 year
  • Thay thế New Line từ Clipboard với batch file (Window)
    1 year
  • Thay thế New Line từ Clipboard với batch file (Window)
    1 year
  • Thay thế New Line từ Clipboard với batch file (Window)
    1 year
  • Macro Hypermesh tạo comp đối xứng, Tạo comps mới full thuộc tính như comps ban đầu
    1 year
  • Macro Hypermesh tạo comp đối xứng, Tạo comps mới full thuộc tính như comps ban đầu
    1 year
  • Show older
Tí Tẹo
No Result
View All Result

Macro Hypermesh tạo comp đối xứng, Tạo comps mới full thuộc tính như comps ban đầu

Macro Hypermesh for Reflecting Comps, New comps same as original comps use tcl

0

Chức năng chính:

-Xóa các comps trống
-Chọn các comps cần lấy đối xứng bởi người dùng
-Lấy thông tin comp đã chọn tạo thông tin comps mới
-Tạo thông tin comps mới và lấy đối xứng

Macro này có thể sử dụng chức năng mặc định Tool >reflect.
Nhưng hạn chế của chức năng mặc định là khi lấy đối xứng nhiều comps cùng lúc, không thể tạo comp mới với thuộc tính tương tự như comp gốc
Macro này sẽ khắc phục điều này, bằng cách dựa trên chức năng mặc định của hypermesh, thực hiện reflect với từng comps được chọn.

Nhược điểm :
Dù Macro đã tạo được theo như mục đích ban đầu, Nhưng vẫn còn tồn tại nhược điểm như, các comps được lấy đối xứng nếu cùng 1 chi tiết thì comp được tạo mới sẽ không được liên kết mới nhau (rời rạc) do vậy, cần thực hiện thêm 1 bước nữa để khắc phục.

Demo

Toàn bộ code, có giải thích bên dưới

proc ReflectComps {} {
	*EntityPreviewUnused props 1
	if {[hm_marklength props 1] !=0} { *deletemark props 1 } 
	*EntityPreviewUnused mats 1
	if {[hm_marklength mats 1] !=0} { *deletemark mats 1 } 
	*EntityPreviewEmpty components 1
	if {[hm_marklength components 1] !=0} { *deletemark components 1 } 
	*clearmarkall 1

	set sol [hm_getsolver id]
	if {sol != 1 } { return } 
        *createmarkpanel comps 1 "Select components to reflect:"
        set listcompreflect [hm_getmark comps 1]
        set maxlist [llength $listcompreflect]
        if {$maxlist==0} {return} else {
		set Plane [hm_getplanepanel "Specify a plane:"]
        for {set i 0} {$i<$maxlist} {incr i} { 
            *createplane 1 1 0 0 0 0 0
            *createmark comps 1 "by id only" [lindex $listcompreflect $i]
			
			set ID_Comp [hm_getmark comps 1]
            set color_comp [hm_entityinfo color comps $ID_Comp]
            set Name_comp [hm_entityinfo name comps $ID_Comp]
			set Name_comp_new "$Name_comp\_reflect$ID_Comp"

			set PropName_new " "
			set PropID 0
			set Mat_ID 0
			set MatName_new " "

			if {[ hm_entityinfo exist props [ hm_getentityvalue comps $ID_Comp "propertyid" 0 ] -byid ] == 1} {
				set PropID [ hm_getentityvalue comps $ID_Comp "propertyid" 0 ]
			}
			if { $PropID == 0 } {
				puts "No props"
				set PropName_new " "
			} else {
				set PropName [ hm_getentityvalue props $PropID "name" 1 ]
				set Thickness_value [hm_getentityvalue props $PropName \$PSHELL_T 0]
				set PropName_new "$PropName\_reflect$ID_Comp"

				if {[ hm_entityinfo exist material [hm_getentityvalue props $PropID "materialid" 0] -byid ] == 1} {
					set Mat_ID [hm_getentityvalue props $PropID "materialid" 0]
				}
				if { $Mat_ID == 0 } {
					puts "No Mat"
					set MatName_new " "
				} else {
					set Mat_name [hm_getentityvalue material $Mat_ID name 1 -byid]
					set MatName_new "$Mat_name\_reflect$ID_Comp"
				}
				
			} 
			set check_MatName_new [hm_entityinfo exist material "$MatName_new"  -byname ]
            set check_PropName_new [hm_entityinfo exist props "$PropName_new" -byname ]
            set check_Name_comp [hm_entityinfo exist comps "$Name_comp_new"  -byname ]
			
            if {($check_Name_comp==1) ||($check_PropName_new==1) ||($check_MatName_new==1)} {
				*clearmark comps 1
                tk_messageBox -message "Compnents already EXISTS in your model!" -title "Please confirm!" -icon warning -type ok
                return
            } else {
				#*collectorcreatesameas comps "$Name_comp_new" "$Name_comp" "" $color_comp
				*collectorcreateonly components "$Name_comp_new" "" $color_comp
				*createmark components 1 "$Name_comp_new"

				if { ($Mat_ID != 0) && ($PropID != 0) } {
   					*collectorcreatesameas materials "$MatName_new" "$Mat_name" "" $color_comp
					*collectorcreatesameas properties "$PropName_new" "$PropName" "$MatName_new" $color_comp
					*propertyupdate components 1 "$PropName_new"
				} elseif { ($Mat_ID == 0) && ($PropID != 0) } {
   					#*collectorcreatesameas properties "$PropName_new" "$PropName" "" $color_comp
					*collectorcreateonly properties "$PropName_new" "$PropName" "" $color_comp
					*propertyupdate components 1 "$PropName_new"
				}
				*clearmark comps 1
				*clearmarkall 1
				*clearmarkall 2 					
				hm_createmark elems 1 "by collector" $ID_Comp
				*duplicatemark elems 1 1
				hm_createmark elems 1 "by collector" "$Name_comp_new"
				eval *createplane 1 [join [join $Plane]]
				*reflectmarkwithoption elements 1 1 0
            }
        }
    }
    *clearmark comps 1
	*clearmarkall 1
	*clearmarkall 2
}

Những phần chính của code

	*EntityPreviewUnused props 1
	if {[hm_marklength props 1] !=0} { *deletemark props 1 } 
	*EntityPreviewUnused mats 1
	if {[hm_marklength mats 1] !=0} { *deletemark mats 1 } 
	*EntityPreviewEmpty components 1
	if {[hm_marklength components 1] !=0} { *deletemark components 1 } 
	*clearmarkall 1

Phần này có thể ảnh hưởng tới mô hình, Đầu tiên, sẽ kiểm tra props, mats không được sử dụng nếu tồn tại props và mats không được sử dụng sẽ xóa. Tương tự với comps, sẽ check comps trống và xóa.
Mục đích phần này đơn giản là, khi thực hiện lại macro này mà chỉ xóa comps, không xóa props và mats trước đó, thì macro sẽ tự động xóa tránh trùng tên.

Tiếp theo là phần chính của macro, cụ thể như sau :

	set sol [hm_getsolver id]
	if {sol != 1 } { return } 

Do macro viết và test trên profile Nastran, để tránh lỗi không mong muốn, macro kiểm tra profile hiện tại, nếu không phải nastran sẽ không thực hiện macro

        *createmarkpanel comps 1 "Select components to reflect:"
        set listcompreflect [hm_getmark comps 1]
        set maxlist [llength $listcompreflect]
        if {$maxlist==0} {return} else {
		set Plane [hm_getplanepanel "Specify a plane:"]
                for {set i 0} {$i<$maxlist} {incr i} { 
                     .....................
                 }
         }

Phần này chính là phần yêu cầu đầu vào cần thiết từ người dùng, có một biến listcompreflect để lấy thông tin về các comp đầu vào và maxlist là biển kiểm tra nếu không có comps nào được lựa chọn bởi người dùng thì sẽ dừng lại. Và ngay sau đó là sử dụng Plane để lưu vector hoặc mặt cần lấy đối xứng qua.
Vòng for ở đây với vai trò dùng để thực hiện lần lượt từng comp đã được chọn.

            *createplane 1 1 0 0 0 0 0
            *createmark comps 1 "by id only" [lindex $listcompreflect $i]
			
            set ID_Comp [hm_getmark comps 1]
            set color_comp [hm_entityinfo color comps $ID_Comp]
            set Name_comp [hm_entityinfo name comps $ID_Comp]
			set Name_comp_new "$Name_comp\_reflect$ID_Comp"

			set PropName_new " "
			set PropID 0
			set Mat_ID 0
			set MatName_new " "

			if {[ hm_entityinfo exist props [ hm_getentityvalue comps $ID_Comp "propertyid" 0 ] -byid ] == 1} {
				set PropID [ hm_getentityvalue comps $ID_Comp "propertyid" 0 ]
			}
			if { $PropID == 0 } {
				puts "No props"
				set PropName_new " "
			} else {
				set PropName [ hm_getentityvalue props $PropID "name" 1 ]
				set Thickness_value [hm_getentityvalue props $PropName \$PSHELL_T 0]
				set PropName_new "$PropName\_reflect$ID_Comp"

				if {[ hm_entityinfo exist material [hm_getentityvalue props $PropID "materialid" 0] -byid ] == 1} {
					set Mat_ID [hm_getentityvalue props $PropID "materialid" 0]
				}
				if { $Mat_ID == 0 } {
					puts "No Mat"
					set MatName_new " "
				} else {
					set Mat_name [hm_getentityvalue material $Mat_ID name 1 -byid]
					set MatName_new "$Mat_name\_reflect$ID_Comp"
				}
				
			} 
			set check_MatName_new [hm_entityinfo exist material "$MatName_new"  -byname ]
            set check_PropName_new [hm_entityinfo exist props "$PropName_new" -byname ]
            set check_Name_comp [hm_entityinfo exist comps "$Name_comp_new"  -byname ]

Phần này sử dụng xen kẽ hm_getmark và hm_entityinfo để đánh dấu comp và lấy, kiểm tra thông tin comp hiện hành. Mục đích để kiểm tra thông tin comp chuẩn bị tạo comp mới theo comp gốc.

				#*collectorcreatesameas comps "$Name_comp_new" "$Name_comp" "" $color_comp
				*collectorcreateonly components "$Name_comp_new" "" $color_comp
				*createmark components 1 "$Name_comp_new"

				if { ($Mat_ID != 0) && ($PropID != 0) } {
   					*collectorcreatesameas materials "$MatName_new" "$Mat_name" "" $color_comp
					*collectorcreatesameas properties "$PropName_new" "$PropName" "$MatName_new" $color_comp
					*propertyupdate components 1 "$PropName_new"
				} elseif { ($Mat_ID == 0) && ($PropID != 0) } {
   					#*collectorcreatesameas properties "$PropName_new" "$PropName" "" $color_comp
					*collectorcreateonly properties "$PropName_new" "$PropName" "" $color_comp
					*propertyupdate components 1 "$PropName_new"
				}
				*clearmark comps 1
				*clearmarkall 1
				*clearmarkall 2 					
				hm_createmark elems 1 "by collector" $ID_Comp
				*duplicatemark elems 1 1
				hm_createmark elems 1 "by collector" "$Name_comp_new"
				eval *createplane 1 [join [join $Plane]]
				*reflectmarkwithoption elements 1 1 0

Phần này được coi là phần trọng tâm, các phần đã giải thích trên sẽ xoay quanh phần này. Nếu đã check các điều kiện đầu vào sẽ tiến hành

  • Tạo comps mới *collectorcreateonly components “$Name_comp_new” “” $color_comp
  • Tạo Mat và Props mới với thông tin theo như comp gốc
    *collectorcreatesameas materials “$MatName_new” “$Mat_name” “” $color_comp
    *collectorcreatesameas properties “$PropName_new” “$PropName” “$MatName_new” $color_comp
  • Và cuối cùng là lấy đối xứng
    *reflectmarkwithoption elements 1 1 0

Dù macro vẫn còn tồn tại nhước điểm, nhưng phần lợi ích mang lại vẫn lớn hơn.
Nếu các bạn có ý tưởng, hay còn thắc mắc chưa thực hiện được, cần cải tiến hãy để lại bình luận, hoặc đăng câu hỏi trong phần cộng đồng nhé.


Related Posts

No Content Available

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Home
  • Community
  • Documents
  • CAE
  • Skill
  • Giải Trí

© 2021 Tí Tẹo

No Result
View All Result
  • Home
  • Community
  • Documents
  • CAE
    • Vật Liệu
    • Toán
  • Skill
  • Giải Trí

© 2021 Tí Tẹo

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In