Jump to content

Script to change the parameters of a plant from "by style" to "by object"


Recommended Posts

Hello,

I'm looking for a way to change the parameters of a plant style automatically on dozens of plants at a time, via a script for example:
I'd like the plant label parameters to change from "by style" to "by object".  Manually, I have to edit each plant and click 14 times...
Does anyone have an idea for changing this automatically, in batch?

Thanks!

 

image.png.763444cb461848ba1e088f0ba614cb03.png

 

  • Like 1
Link to comment
  • 5 months later...
  • 9 months later...
  • 1 year later...

Hi,

 

I was tired of having to run the MassEditPlantStyle script for each label field, so after some research, I created a small marionette node that allows you to change all the parameters of the plant labels in the file by setting them “by style” or “by instance.”

The other node below allows you to configure each field “by style” or “by instance” separately, which affects all the plants in the file.

It's in French, and if I have some time, I'll translate it into English.

It'll be easier and faster that way!

If you prefer a script:
 

import vs

# --- VARIABLES GLOBALES ---
g_choix_tag = '16383'
g_plant_folder = ''
kID_TextInfo = 10
kID_CheckStyle = 11
kID_CheckInstance = 12
kID_FolderName = 13
kID_FolderMenu = 14
styles_modifies = []


# --- RÉCUPÉRATION DES DOSSIERS DE SYMBOLES ---
def get_plant_folders():
    folders = []
    listID, numItems = vs.BuildResourceList(16, 0, '')
    for i in range(1, numItems + 1):
        objH = vs.GetResourceFromList(listID, i)
        if objH:
            parentH = vs.GetParent(objH)
            if parentH:
                typeN = vs.GetTypeN(parentH)
                name = vs.GetName(parentH)
                if typeN == 92 and name and name not in folders:
                    folders.append(name)
    return sorted(folders)


# --- DIALOG ---
def CreateMyDialog():
    dialog = vs.CreateLayout("Configuration des Tags de Plante", True, "Appliquer", "Annuler")
    vs.CreateStaticText(dialog, kID_TextInfo,
        "Les modifications seront appliquées aux plans placés sur le layer actif", 60)
    vs.CreateCheckBox(dialog, kID_CheckStyle, "Passer en mode : By STYLE")
    vs.CreateCheckBox(dialog, kID_CheckInstance, "Passer en mode : By INSTANCE")
    vs.CreateStaticText(dialog, kID_FolderName, "Dossier ressources plantes :", 40)
    vs.CreatePullDownMenu(dialog, kID_FolderMenu, 40)  # ← ID séparé pour le menu

    vs.SetFirstLayoutItem(dialog, kID_TextInfo)
    vs.SetBelowItem(dialog, kID_TextInfo, kID_CheckStyle, 0, 0)
    vs.SetBelowItem(dialog, kID_CheckStyle, kID_CheckInstance, 0, 0)
    vs.SetBelowItem(dialog, kID_CheckInstance, kID_FolderName, 0, 4)
    vs.SetRightItem(dialog, kID_FolderName, kID_FolderMenu, 0, 0)
    return dialog


def make_handler(dialog, folders):
    def DialogHandler(item, data):
        global g_choix_tag, g_plant_folder

        if item == -1 or item == 12255:  # SetupDialogC — les deux valeurs selon la version
            vs.SetBooleanItem(dialog, kID_CheckInstance, True)
            g_choix_tag = '16383'
            for folderName in folders:
                vs.AddChoice(dialog, kID_FolderMenu, folderName, 0)
            if folders:
                vs.SelectChoice(dialog, kID_FolderMenu, 0, True)

        elif item == kID_CheckStyle:
            vs.SetBooleanItem(dialog, kID_CheckInstance, False)
            vs.SetBooleanItem(dialog, kID_CheckStyle, True)
            g_choix_tag = '0'

        elif item == kID_CheckInstance:
            vs.SetBooleanItem(dialog, kID_CheckStyle, False)
            vs.SetBooleanItem(dialog, kID_CheckInstance, True)
            g_choix_tag = '16383'

        elif item == 1:  # Bouton Appliquer
            selectedIndex = vs.GetSelectedChoiceIndex(dialog, kID_FolderMenu, 0)
            if selectedIndex >= 0:
                g_plant_folder = folders[selectedIndex]

    return DialogHandler


# --- LOGIQUE RESSOURCES ---
def get_resources_in_folder(folderName, resourceType=16):
    objList = []
    hFolder = vs.GetObject(folderName)
    if hFolder is None:
        return objList
    listResourcesID, numItems = vs.BuildResourceList(resourceType, 0, '')
    for cnt in range(1, numItems + 1):
        objH = vs.GetResourceFromList(listResourcesID, cnt)
        if objH is not None:
            parentH = vs.GetParent(objH)
            if parentH == hFolder:
                tempStr = vs.GetNameFromResourceList(listResourcesID, cnt)
                objList.append((tempStr, objH))
    return objList


# --- LOGIQUE STYLE ---
def modifier_pio_in_style(hSymDef):
    hChild = vs.FInGroup(hSymDef)
    while hChild:
        if vs.GetTypeN(hChild) == 86:
            vs.SetRField(hChild, 'Plant', '__Tag_value_flags', g_choix_tag)
            vs.ResetObject(hChild)
            break
        hChild = vs.NextObj(hChild)
    vs.ResetObject(hSymDef)


def modifier_styles_depuis_ressources(folderName):
    resources = get_resources_in_folder(folderName, resourceType=16)
    for styleName, hSymDef in resources:
        if styleName not in styles_modifies:
            modifier_pio_in_style(hSymDef)
            styles_modifies.append(styleName)


# --- LOGIQUE INSTANCES ---
def modifier_instance(h):
    if vs.GetTypeN(h) == 86:
        vs.SetRField(h, 'Plant', '__Tag_value_flags', g_choix_tag)
        vs.ResetObject(h)


# --- EXECUTION ---
dialog = CreateMyDialog()
folders = get_plant_folders()

if vs.RunLayoutDialog(dialog, make_handler(dialog, folders)) == 1:
    styles_modifies = []
    if g_plant_folder:
        modifier_styles_depuis_ressources(g_plant_folder)
    vs.ForEachObject(modifier_instance, "(T=86)")
    vs.ReDrawAll()
    mode_str = "by STYLE" if g_choix_tag == '0' else "by INSTANCE"
    vs.AlrtDialog(f"Succès : Toutes les étiquettes de plantes sont maintenant en mode {mode_str}")

 

 

image.png

Plants tags by Style or by Instance V1_1.vwx

Edited by Nico_be
The style was not modified in the resources, but now everything works.
  • Like 3
Link to comment
  • Vectorworks, Inc Employee

@Nico_be, that is a nice script. I'm sure that went much faster than having to go through one setting at a time.

 

If you don't have access to it, I would suggest opening the file with the plants you want to change and then start the Plant Style Manager. You can batch edit anything that is allowed with the identical setting there, and this includes the by style/by instance settings (You can't batch edit things like plant ID and style name, as they must be unique in the file).

  • Like 1
Link to comment
10 minutes ago, Katarina Ollikainen said:

@Nico_be, that is a nice script. I'm sure that went much faster than having to go through one setting at a time.

 

If you don't have access to it, I would suggest opening the file with the plants you want to change and then start the Plant Style Manager. You can batch edit anything that is allowed with the identical setting there, and this includes the by style/by instance settings (You can't batch edit things like plant ID and style name, as they must be unique in the file).

@Katarina Ollikainen Yes, but I have to modify column by column (field by field), and during my last attempt, VW crashed.  It was on a file with 2,000 plants.
Here, with this script, it's much smoother and faster.

  • Like 1
Link to comment

Unfortunately, I just realized that although the change is visible in the OIP, it is not reflected in the plant style; the settings remain unchanged when editing the plant...

If anyone has any ideas, I'm interested!🤪

 

EDIT:See original message, everything is OK now.

Edited by Nico_be
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...