Jump to content

How to get the 3d position of a label?


Recommended Posts

hey marco, to clarify - you want a nominal surface point with dn check instead of a deviation label on the surface comparison? 

 

import gom
import numpy as np

gom_part = gom.app.project.parts[0]
label = gom.app.project.inspection['Surface comparison 2'].deviation_label['Surface comparison 2.1']
coord = np.array(label.data.coordinate)
normal = np.array(label.data.normal)

x,  y,  z  = coord.reshape(-1)
nx, ny, nz = normal.reshape(-1)

gom.script.cad.show_element_exclusively (elements=gom.ElementSelection ({'category': ['key', 'elements', 'part', gom_part, 'explorer_category', 'nominal_part']}))
##nominal surface pt
nominal_surface_pt = gom.script.primitive.create_surface_point (
	name_expression='Point_from_label', 
	point={'interpolated': True, 'normal': gom.Vec3d (nx, ny, nz), 'point': gom.Vec3d (x,y,z), 'target': gom_part})

##make sure its attached to cad surface
gom.script.cad.adapt_elements_to_cad (
	elements=[nominal_surface_pt], 
	normal_from_cad=True, 
	position_from_cad=True)

##mp
MCAD_ELEMENT=gom.script.inspection.measure_by_intersection_with_mesh (
	elements=[nominal_surface_pt])
#check	
MCAD_ELEMENT=gom.script.inspection.inspect_dimension (
	csys=gom.app.project.nominal_elements['system_global_coordinate_system'], 
	elements=[nominal_surface_pt], 
	nominal_value=0.0, 
	nominal_value_source='fixed_value', 
	type='normal')

 

ah, label position in 3d view. thats a tough one, you could prob use that apply selection function + label offset in 3d view to get the gom.Vec3d,  but i'm not sure theres a function to then set that attribute.

I tried 


for label in gom.ElementSelection ({'category': ['key', 'elements', 'part', gom_part, 'explorer_category', 'inspection', 'object_family', 'deviation_label', 'type', 'deviation_label_surface']}):
	gom.script.explorer.apply_selection(selection = [label]) 
	print(label.label_offset_in_3d_view)
	
	gom.script.sys.edit_properties (
		data=[label], 
		label_show=True,
		label_offset_in_3d_view = gom.Vec3d (5.29687008412543, 2.842170943040401e-14, -7.7582401624698605) )

which prints all the positions, but doesnt work for setting a new position. 
maybe throw em all to screen edge? 

 

This is the code I use, but for some label it doesn't work. I don't know why. What command I can use to put them, if label offset is None, to the screen edge?

def dn_in_label():
#Pulizia report
    pagine_da_pulire_lst=[]
    
    for pagina_da_pulire in gom.app.project.reports:
        pagine_da_pulire_lst.append(pagina_da_pulire)
    
    gom.script.report.update_report_page (
        pages=pagine_da_pulire_lst, 
        used_alignments='report', 
        used_digits='report', 
        used_legends='report', 
        used_stages='current', 
        used_units='report')
    
    reports = gom.app.project.reports
    for report in reports:
        print(report)
        pages = report.pages
        for page in pages:
            print(page)
            elements = page.elements
            for element in elements:
                print(element)
                if element.get('type') == 'figure_snapshot_frame':
                    componente = element.parts_in_report
                    print(componente) # stampa il valore di 'componente'
                    part = gom.app.project.parts[componente]
                    gom.script.report.restore_3d_view_from_report_page(page=element)
    
                    visible_dn_lst = []
                    visible_measure_lst=[]
                    # Filtra i punti che contengono ".dN" e sono visibili
                    for dn in gom.app.project.inspection:
                        print (dn)
                        print (dn.scalar_value)
                        if ".dN" in dn.name:
                            if dn.is_visible:
                                visible_dn_lst.append(dn)
                        if dn.scalar_value is not None and dn.scalar_value > 0:
                            if dn.is_visible:
                                visible_measure_lst.append(dn)
                    print (visible_measure_lst)
                    gom.script.cad.hide_element (elements=visible_measure_lst)
                    # Per ogni punto dN visibile
                    for dn in visible_dn_lst:
                        coordinata_dn = dn.center_coordinate
                        normale_dn = dn.normal
                        dn_pos = dn.label_offset_in_3d_view
                        # Per ogni confronto superficie visibile
                        for confronto in gom.app.project.inspection:
                            print (confronto)
                            if confronto.get('type') == 'surface_comparison' and confronto.is_visible:
                                print(confronto)
                    
                                # Chiamata allo script per ogni coppia punto/confronto
                                MCAD_ELEMENT = gom.script.inspection.inspect_by_deviation_label(point={'interpolated': True, 'normal': normale_dn, 'point': coordinata_dn, 'target': confronto})
                                gom.script.cad.hide_element (elements=[dn])
                                label=MCAD_ELEMENT
                                print (label)
                                gom.script.sys.edit_properties (
                                    data=gom.ElementSelection (label, {'attachment_group': [None, 'criterias']}), 
                                    elem_show=True, 
                                    label_show=True, 
                                    label_template='Annotazione di Deviazione', 
                                    label_template_uuid='3807e37f-a68f-4bed-b65c-61f0ddd1000c')
                                
                                
                                gom.script.cad.set_label_position(elements=[label],offset=dn_pos)
                    gom.script.sys.switch_to_report_workspace()
                    gom.script.report.overwrite_report_page(target=element)

hmm, didnt know that was a function, (would be nice if we had a global list of these things somewhere) 

for labels on screen edge: 
gom.script.cad.set_label_distribution_mode (distribution_mode='border')

try and drop the s) from elements, and dont use a list. 

docstring is kinda confusing, 
try and just use the arguments (element & offset) 

print(gom.script.cad.set_label_position.__doc__)

cad.set_label_position (Move Label) - Move Label

Parameters:

Name       | Description                                               | Type                                   | Optional
--------------------------------------------------------------------------------------------------------------------------
element    | defines the name of the element                           | Tom::Reference                         | No      
elements   | defines the names of the elements                         | Tom::MCADCmd::Traits::ElementSelection | No      
position   | defines the position of the label                         | Core::Types::BaVec<2,double>           | No      
offset     | defines the 3d offset of the label                        | Core::Types::BaVec<3,double>           | No      
offsets    | defines the 3d offset of the label                        | QVariantList                           | No      
view_index | defines the index of the view, where the label gets moved | uint                                   | Yes    


position seems to be is in lieu of offset (?)- or atleast thats what the error said when I tried to use it. 

gom_part = gom.app.project.parts[0]
for label in gom.ElementSelection ({'category': ['key', 'elements', 'part', gom_part, 'explorer_category', 'inspection', 'object_family', 'deviation_label', 'type', 'deviation_label_surface']}):
	gom.script.explorer.apply_selection(selection = [label]) 
	print(label.label_offset_in_3d_view)
	
	
	gom.script.cad.set_label_position(
		element=label,
#		position = gom.Vec2d(15,25),
		offset=gom.Vec3d (20,-20,-20)
		)

^^seems to work like the 'justify label' button 

anyways, good luck!
 

×
×
  • Create New...