Jump to content

keywords aus Names des Netzes ableiten


---
 Share

Recommended Posts

Hallo zusammen,

ich nehme mal an, dass folgendes per Skript realisierbar ist. Es sollen keywords aus dem Namen des IST-Netzes in die keyword-Liste eingetragen werden.
Also wenn der Name des Netzes immer folgendes Schema hat "Auftragsnummer_Kunde_Gießdatum_...", dass man daraus automatisch die keywords "Auftragsnummer", "Kunde", Gießdatum" usw. eingetragen bekommt. Das Ganze dann über alle Stufen des Projekts.

Vielen Dank

Link to comment
Share on other sites

This can be done in script. Altering keywords is in AddOn examples - i think there is in examples a way to get mesh name, so this script can be within a few lines of code.

I am still on beginning of programming on this, so i don't know how to make it automatically after mesh insertion - for now i would make it to run after button click.
Also you can define some settings for this script in Inspect preferences, so you don't need to hardcode scheme.

Link to comment
Share on other sites

Hi,

To get the mesh name:

print(f"{gom.app.project.parts['Training Object'].actual.name=}")
# => Zeiss training object (extracted) 1.red Material 1

# Using the part index instead of the part name
print(f"{gom.app.project.parts[0].actual.name}")
# => Zeiss training object (extracted) 1.red Material 1

If the mesh element has element keywords:

for keyword in gom.app.project.parts['Training Object'].actual.element_keywords:
	print(f"{keyword=}, value: {gom.app.project.parts['Training Object'].actual.get(keyword)}")
# => keyword='user_Test', value: Zeiss training object

To get the mesh names from stages: see Working with stages — App Development Documentation.


To split a name like Auftragsnummer_Kunde_Gießdatum_... with underscore ('_') as separator:

auftragsnummer, kunde, giessdatum = gom.app.project.parts[0].actual.name.split('_')


Please refer to Project keywords handling — App Development Documentation for writing project keywords.

Best regards,

Matthias

Edited
Link to comment
Share on other sites

Here is safe working script if anyone needs

# -*- coding: utf-8 -*-

import gom

# Getting name from mesh
mesh_name = gom.app.project.parts[0].actual.name

# Saving into variables - delimiter: "_"
keyword_list = mesh_name.split('_')

# Default values
_order    = ''
_customer = ''
_date     = ''

# Filling cycle
for x in range( len(keyword_list) ):
	if   x == 0:
		_order = keyword_list[x]
	elif x == 1:
		_customer = keyword_list[x]
	elif x == 2:
		_date = keyword_list[x]

# Storing into project keywords
gom.script.sys.set_project_keywords (
	keywords={ 'order': _order, 'customer': _customer, 'date': _date },
	keywords_description={ 'order': 'Order number', 'customer': 'Customer', 'date': 'Mold date' } )
	
# Doc
'''
#Default values -> define own variable names used in scripts and their default value

#Filling cycle -> continue to fill all needed keywords
	cycle runs from 0 as first element
	
#Storing into keywords
	Example definition:

	keywords={'ORDER': _ORDER_},
	keywords_description={'ORDER': 'DESCRIPTION TEXT'} <-- needed for creating new keyword if not existing
	
	'ORDER' -> keyword name -> in report it's called by 'USER_ORDER'
	_ORDER_ -> your variable
	'DESCRIPTION TEXT' -> Visible text on keyword form
'''

 

Link to comment
Share on other sites

 Share

×
×
  • Create New...