# # Copyright 2014 (c) Pointwise, Inc. # All rights reserved. # # This sample Pointwise script is not supported by Pointwise, Inc. # It is provided freely for demonstration purposes only. # SEE THE WARRANTY DISCLAIMER AT THE BOTTOM OF THIS FILE. # # ############################################################################# ## ## squeezeCon-Simple-Comments.glf ## ## COPY CONNECTOR AND SCALE TO FIT BETWEEN TWO POINTS ## ## Allows you to copy a connector and specify the desired final endpoints. ## 0. Choose connector (can be done prior to executing the script) ## 1. Choose first point for beginning of new connector ## 2. Choose second point for end of new connector ## ## Replaces two-step (multi-click) process of 1) Copy-Paste-Translate, Accept, ## and 2) Edit-Transform-Scale. Script is necessary since the endpoint of the ## temporary translated connector in the paste mode is not a pickable point. ## ############################################################################# package require PWI_Glyph 2 ## NOTE: A line that begins with a '#'-sign is a comment. ## Set selection mask ## -requireConnector {} specifies any connector, regardless of dimension or ## domain affiliation set mask [pw::Display createSelectionMask -requireConnector {}] ## Get the entities currently selected in the GUI pw::Display getSelectedEntities -selectionmask $mask curSelection ## Place all connectors in the current selection in the variable, $con set con $curSelection(Connectors) ## Pick first point used to determine the final location of the connector set pt2 [pw::Display selectPoint -description \ "Select first point." -connector [list]] ## Pick second point used to determine the final location of the connector set pt3 [pw::Display selectPoint -description \ "Select second point." -connector [list]] ## Find end of connector closest to the first point picked set pt1_a [$con getXYZ -arc 0.0] set pt1_b [$con getXYZ -arc 1.0] ## Print the two end points of the original connectors, $pt1_a and $pt1_b puts $pt1_a puts $pt1_b ## Compute the distance (length) between the two end points and $pt2 set diff_a [pwu::Vector3 length [pwu::Vector3 subtract $pt1_a $pt2]] set diff_b [pwu::Vector3 length [pwu::Vector3 subtract $pt1_b $pt2]] if {$diff_a <= $diff_b} { ## If diff_a < diff_b, this means that pt1_a was closer to pt2 set pt1 $pt1_a } else { ## If diff_b < diff_a, this means that pt1_b was closer to pt2 set pt1 $pt1_b } ## Define translation vector set transVec [pwu::Vector3 subtract $pt2 $pt1] ## Set up paste command pw::Application clearClipboard pw::Application setClipboard [list $con] ## Start paste mode set pasteMode [pw::Application begin Paste] ## Get the temporary entities created in the Paste mode (i.e. the new ## entities created from the clipboard). set modEnts [$pasteMode getEntities] ## Start modify mode to apply the translation and scaling operations set modMode [pw::Application begin Modify $modEnts] ## Translate connector pw::Entity transform [pwu::Transform translation $transVec] $modEnts ## Get the translated connector set newCon [lindex $modEnts 0] ## Get beginning point of new connector set pt4 [$newCon getPosition -arc 0] ## Make sure pt4 is set to the end of pasted connector opposite pt2 if {[pwu::Vector3 equal -tolerance 1e-6 $pt2 $pt4]} { set pt4 [$newCon getPosition -arc 1] } ## Scale pasted connector pw::Entity transform [pwu::Transform calculatedScaling $pt2 $pt4 \ $pt3 [pw::Grid getNodeTolerance]] $newCon $modMode end $pasteMode end pw::Application clearClipboard # # DISCLAIMER: # TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, POINTWISE DISCLAIMS # ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED # TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE, WITH REGARD TO THIS SCRIPT. TO THE MAXIMUM EXTENT PERMITTED # BY APPLICABLE LAW, IN NO EVENT SHALL POINTWISE BE LIABLE TO ANY PARTY # FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES # WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF # BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE # USE OF OR INABILITY TO USE THIS SCRIPT EVEN IF POINTWISE HAS BEEN # ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND REGARDLESS OF THE # FAULT OR NEGLIGENCE OF POINTWISE. #