Jump to content
Developer Wiki and Function Reference Links Read more... ×
Ben Wingrove

Help finding center of Symbol!

Recommended Posts

I am trying to make a simple Marionette to rotate certain symbols by name in my drawing, every time I run the script it is offsetting the center of the symbol and moving it around, I have tried different nodes to get the center but they all seem to have the same effect!! I have been trying to get this to work for a few days now and could really do with some pointers.

 

Thanks

 

B

 

5a1aff49bc9b0_ScreenShot2017-11-26at9_44_39AM.thumb.png.d01a7505819e023b192c5377374eb977.png

 

Share this post


Link to post

Interesting. Have you tried using the Rotate node instead of "Set 3D Rotation"? I think you don't actually need to find the symbol centre either, the rotate node will rotate the symbol about its centre if no rotation pivot is provided.

Edited by Stephan Moenninghoff

Share this post


Link to post

This node gives you the center of the Bounding Box.

 

'''
    Changed on 22.02.2016 : Wrong Var was used in the calcul. of the center    
    Changed on 04.04.2016 : Created the 'def GetBBoxN (h)'
    Changed on 18.04.2016 : set Initialize function: Marionette.InitializeView
    Changed on 27.11.2017 : Force TopView
    
    author: patrick winkler
'''

import vs
import Marionette

@Marionette.NodeDefinition
class Params(metaclass = Marionette.OrderedClass):
    this = Marionette.Node( 'Get Bounding Box' )
    this.SetDescription("Returns the bounding box's coordinates of the projection of an object on the screen plane")
    
    # IMPORTANT:  SetThe View to Top while Execution - The BB Values are otherwise incorrect!!!!
    this.SetInitFunc(Marionette.InitializeView)
    this.SetFinalFunc (Marionette.RestoreView)    
    
    obj = Marionette.PortIn(vs.Handle(0))
    obj.SetDescription( "The input object" )
    
    topL2D = Marionette.PortOut()
    topL2D.SetDescription( "The top left coordinates of the bounding box" )
    
    botR2D = Marionette.PortOut()        
    botR2D.SetDescription( "The bottom right coordinatesr of the bounding box" )

    width = Marionette.PortOut()        
    width.SetDescription("The width of the bounding box.")    
    
    height = Marionette.PortOut()        
    height.SetDescription("The height of the bounding box.")

    center = Marionette.PortOut()        
    center.SetDescription("The centerpoint of the bounding box.")

def RunNode(self):    
    def GetBBoxN (h, top_view = True):
        '''
            Returns top left point, bottom right point, width, height and center of the object bounding box (as tuple).
            
            IMPORTANT: The result depends on the view in VW if top_view is False. 
        '''    
        if top_view:
            # Change the view to Top temporarily
            orig_view = vs.GetView()
            vs.SetView(0, 0, 0, 0, 0, 0)
        
        box = vs.GetBBox(h)
        topL2D = box[0]
        botR2D = box[1]
        
        center = [None, None]
        
        BB_width  = botR2D[0] - topL2D[0]
        BB_height = topL2D[1] - botR2D[1]
            
        center[0] = topL2D[0] + BB_width / 2
        center[1] = topL2D[1] - BB_height / 2
        
        center = tuple (center)
            
        if top_view:
            # Restore the original view
            xAngle, yAngle, zAngle, offset = orig_view
            xDistance, yDistance, zDistance = offset
            
            vs.SetView(xAngle, yAngle, zAngle, xDistance, yDistance, zDistance)
        
        return (topL2D, botR2D, BB_width, BB_height, center)
    
    obj = self.Params.obj.value    
    
    if not obj:
        raise ValueError('No object handle was provided!')
    
    topL2D, botR2D, BB_width, BB_height, center = GetBBoxN(obj, top_view = True)
    
    # SET THE OUT PORTS
    self.Params.topL2D.value = topL2D
    self.Params.botR2D.value = botR2D
    
    self.Params.width.value = BB_width
    self.Params.height.value = BB_height
    
    self.Params.center.value = tuple (center)
    

 

 

Share this post


Link to post

To make sure the center stays at the same location  the bounding box must always have the same size.

This can be accomplished by palcing an invisible circle into the symbol. ( set fill and penstyle to empty.)

 

5a1c2eb12ee8d_Bildschirmfoto2017-11-27um16_24_58.thumb.png.489230ef97008c9e1410305e9b48f526.png

Edited by Patrick Winkler

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×