Jump to content
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.








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

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.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)
    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.)



Edited by Patrick Winkler

Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


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.

  • Create New...