Jump to content

how can i access the vs.GetNumFaces(h) in symbols


Recommended Posts

Hi Everyone

 

Becuase we encountered a problem where almost every Symbold that has been modelled in Vectorworks has chaotic Facenormal directions.

This turns into a problem once you use CAD Data in realtime such as VR & AR where we have only enough drawcall time for one face side to be drawn.

 

I made a little script that will help us fix Normals on Faces, however this works only if we completely ungroup Symbols, but we can't do that because we lose all our Database connections.

 

This is the script that works only on a ungrouped mesh:
 

import vs
 
def uniform_surface_normals():
    # Get the handle to the first selected object on the active layer
    h = vs.FSActLayer()
 
    # Check if an object is selected
    if h is None:
        vs.AlrtDialog('No object selected!')
        return
 
        num_faces = vs.GetNumFaces(h)
 
        for i in range(i, num_face + 1):
 
            normalX, normalY, normalZ = vs.GetPolyFaceNormal(h, 1)
           
            vs.GetPolyFaceNormal(h, i, 0, 0, 1)
 
    vs.ReDraw()
 
# Run the function
uniform_surface_normals()

 

it Would be amazing if you could help me doing this on selected Symbols, i was unable to get into the symbols with phyton.

 

best regards

Pascal

Link to comment

Hello, @pascalachermann.

   It would help a lot if you'd post a sample VW file that contained symbols that you were trying to process. Also, please include a symbol with before and after states so we can see what the answer should look like, even if you have to do it by hand. Guessing is not a good way to go when trying to solve someone else's problem.

 

vs.GetPolyFaceNormal() and vs.GetPolyFaceNormal() are not a built-in VW functions, so you might want to post them, too.

 

Thanks,

Raymond

 

  • Love 1
Link to comment

@pascalachermann I see you are in Switzerland.  It is like you are using the Computerworks German localized version.

 

Computerworks does a great job and has added a substantial amount of content to VW, including some "extra" Vectorscript commands that don't exist in the US version that Raymond and I use. The added features include the FaceNormal functions.

 

So while we can help with the structure and syntax of your script, we will not be able to run and test it. 😞

 

  • Like 1
Link to comment
  • 4 weeks later...

Hello @pascalachermann,

   I was able to open your new file. However, I still am not able to run your Python script to see what it does, because it contains unique calls that are only available to you on your VW installation, namely: vs.GetNumFaces() and vs.GetPolyFaceNormal(). I think your best bet is to find someone with the same VW installation to help you. If there is a way to post the workings of those two functions, then more people on this forum might be able to lend a hand.

 

All the best,

Raymond

Link to comment

Hi @MullinRJ thanks for trying, just to make sure, my functions are only working of you ungroup the symbol.
they should then work.

 

However that is my problem, im not supposed to ungroup them, becuase it breaks some connection to the database, according to my client.

 

Ideally would be if this script can be enhanced to traverse inside the symbol and walk over ther vertices without having them to ungroup and open.

 

🙂

Link to comment

hello @pascalachermann,

 

i haven’t been here for long and I’m more focused on Marionette. I haven’t had much contact with the script files yet.

It wasn’t easy to understand at first what Vectorworks is doing. The symbol objects in a drawing are of type 15, those in the library are of type 16.

I think the script explains most of it. I tested it with classes. Attached you will also find my file where my tests and the “final” script are located.

You will also notice that not all objects change. This is because they are in a groups. Additionally, the objects for the script must be in the first level of the resource manager. This can all be changed. It just increases the complexity, and I wanted to know from you first if it even works. It seemed to me that time was also a bit pressing.

I didn’t know which version you are using. I’m on 2023, so I got a message and therefore exported to 2019.

I’m not sure where vs.redraw() should go.

I have too little experience with the syntax and normal-maps in Vectorworks, especially since I can’t debug due to the missing syntax from your tool.

But whatever 😄:

import vs

def change_class_to_02():
    # Get the first object on the active layer
    obj = vs.FActLayer()
    
    if obj == vs.Handle(0):
        vs.AlrtDialog("No objects found on the active layer.")
        return
    
    while obj != vs.Handle(0):
        # Get the type of the object
        obj_type = vs.GetTypeN(obj)
        
        # Check if the object is a symbol
        if obj_type == 15:  # 15 represents a symbol
            
            # Get the linked source symbol
            symbol_name = vs.GetSymName(obj)
            
            # Search the library for the source symbol
            sym_def = vs.FSymDef()
            symbol_found = False
            while sym_def != vs.Handle(0):
                if vs.GetName(sym_def) == symbol_name and vs.GetTypeN(sym_def) == 16:  # 16 represents a symbol definition
                    symbol_found = True
                    
                    # Iterate through all objects in the symbol definition
                    sym_def_obj = vs.FInSymDef(sym_def)
                    if sym_def_obj == vs.Handle(0):
                        vs.AlrtDialog(f"No sub-objects found in source symbol {vs.GetName(sym_def)}.")
                    while sym_def_obj != vs.Handle(0):
                        # ----------------pascalachermann--------------------------
						num_faces = vs.GetNumFaces(h)
						for i in range(i, num_face + 1):
							normalX, normalY, normalZ = vs.GetPolyFaceNormal(h, 1)
							vs.GetPolyFaceNormal(h, i, 0, 0, 1)
						# ----------------pascalachermann--------------------------							
							vs.ReDraw() #<<<<<<< ????!!!!????
						# ----------------pascalachermann--------------------------
                        sym_def_obj = vs.NextObj(sym_def_obj)
                    break
                
                sym_def = vs.NextSymDef(sym_def)
            
            if not symbol_found:
                vs.AlrtDialog(f"Source symbol {symbol_name} not found in library.")
        
        # Move to the next object on the active layer
        obj = vs.NextObj(obj)
    
    vs.AlrtDialog("All objects have been processed.")

# Execute the function
change_class_to_02()

 

I’m curious to see if you can make something out of this.

Best regards

TS V_01_Zuzzla_v2019.vwx

  • Like 1
Link to comment

What also occurred to me:

Is it important to only edit the objects in the drawing/construction layer, or do you want to convert all the symbols in the file anyway?

This might simplify things a bit. We could define a folder named “NumFaces”. When executed, the script will try to apply to all symbols in it.

Or on the entire file, that would also be possible.

Link to comment
8 hours ago, pascalachermann said:

Hi @MullinRJ thanks for trying, just to make sure, my functions are only working of you ungroup the symbol.
they should then work.

 

However that is my problem, im not supposed to ungroup them, becuase it breaks some connection to the database, according to my client.

 

Ideally would be if this script can be enhanced to traverse inside the symbol and walk over ther vertices without having them to ungroup and open.

 

 

Hello @pascalachermann,

   In theory, YES, you should be able to work inside a symbol definition. The problem I face concerns the two functions you use in your script that are not native to VW. Even if I guess how to structure your code, I cannot test it because it will not compile on my machine. I cannot even test the example that @Zuzzla posted, again because it uses the same two functions. Try his/her example and see if it works, then let us know how it went. 
 

All the best,

Raymond

 

  • Like 2
Link to comment

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.

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

×
×
  • Create New...