Jump to content

loop to capture all inspection elements in a list


---
 Share

Recommended Posts

Hi Tim , inspections can be in different caretgories , say scalar and GDanT.   You will need a loop per type.

Go to F2 in the edit script window, select top level element type, enter .  Itll generate the syntax of the container.

for i in containertext:

    I.get (name). Etc.  Again F2 gives list of properties.

 

Hope this helps

Link to comment
Share on other sites

Please sign in to view this username.

The tree I have is GD&T > Surface Profile > Profile Checks

When I highlight each and hit enter I get the below output:

gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'inspection', 'object_family', 'gdat']})
gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'inspection', 'object_family', 'gdat', 'type', 'surface_profile']})
gom.app.project.inspection['CHECK_19_PROF']
gom.app.project.inspection['CHECK_20_PROF']
gom.app.project.inspection['CHECK_21_PROF']
gom.app.project.inspection['CHECK_22_PROF']

 

I don't really understand your previous reply on how to construct a for loop to loop thru these names and output them into a list. 

I'm familiar with all types of loops, but your syntax confused me.  What is the containertext, I assume it is a dict since you are using a get command, but then you have 'name' inside the get command and I don't understand what name is either?

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Hi Tim,

Sorry if confusing , its one of those that if i was still able to do a remote screenshare then could probably explain in 10 minutes!

Ill try...

The containertext i was referring to was an example "gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'inspection', 'object_family', 'gdat']})"

 name was just an example element property that is accessible .

So rather than looping and printing the full element container  gom.app.project.inspection['CHECK_21_PROF'].  It would generate CHECK_21_PROF

 

gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'inspection', 'object_family', 'gdat']}) will loop round all gdandt elements , regardless of type. 

so for example you could have a conditional statement in the loop based on type of check.

gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'inspection', 'object_family', 'gdat', 'type', 'surface_profile']}) will only loop through surface profile elements.

so your code could look something like

For i in gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'inspection', 'object_family', 'gdat', 'type', 'surface_profile']})

Elementname=I.get(name)

Print ( elementname)

 

This will generate the list of surface profile names in the command dialogue in the script editor.

If you needed something more elaborate , like writing to a csv file , id recommend having a look at Python.org 

I hope that helps!

 

Link to comment
Share on other sites

Please sign in to view this username.

I'm still not able to extract the name of the element with your code.  i.get(name)    name is not defined error....name is the key of the dictionary in python. I don't know what the key is for extracting the name of the element.

When I use the below code:

for i in gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'inspection', 'object_family', 'gdat', 'type', 'surface_profile']}):
    print(str(i))

I get the below output:

gom.app.project.inspection['CHECK_10_PROFILE']

gom.app.project.inspection['CHECK_20_PROFILE']

gom.app.project.inspection['CHECK_30_PROFILE']

 

I would like to just return the name inside the single quotation marks, therefore I would need the name of the  key for the get() command.

 

I went ahead and extracted the name manually with the below code for now. If you can help me out with the name of the key that I put inside the get() command that would be great.

for i in gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'inspection', 'object_family', 'gdat', 'type', 'surface_profile']}):

	# define that we are looking for name in between single quotation marks
	pattern = r"'([^']*)'"

	# re.search retrieves the name in between the single quotation marks as a list
	name = re.findall(pattern, str(i))
	
	# print the name, not the list
	print(name[0])

 

Link to comment
Share on other sites

I was able to finally retrieve the name of the check. I missed that you need the quotation marks around the name. It was a little hard to understand your explanations due to many syntax errors.

 

This is the code that worked to extract only the name of the check from all the surface profile checks:

	for i in gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'inspection', 'object_family', 'gdat', 'type', 'surface_profile']}):
		print(i.get('name'))

Thanks for pushing me in the right direction.

 

Edited
Link to comment
Share on other sites

Glad you managed to find it.

I sadly am not in a position to post from a pc with the software access so the syntax was from my mind / written on my tablet whilst relaxing on holiday 😉

Hope it didnt cause too much frustration and you can get to the end goal.

Link to comment
Share on other sites

Please sign in to view this username.

I figured you were typing on your phone...no worries, your syntax issues forced me to learn a couple new things. We have a program that checks all features, then another program that checks 70% of the features. The problem for me is when I'm asked to change the main program I need to save it out as the 70% program with only those checks. So I open the 70% program....store those checks in a list....open the main program and force it to hide the 30% checks I don't need and re-save it as that program.  It is a cute little program that saves me a lot of time.

Link to comment
Share on other sites

Please sign in to view this username.

 Glad it worked out anyway.

As a question on your use case.   Do you have different scanning progams for 70pct 30pct?   

If no i would be tempted to do your report control inside 1 project by tags etc.   Might save further time , particularly on version control?

 

Link to comment
Share on other sites

Please sign in to view this username.

No they are the same scan. I'm very curious about the 'tags' because I consider myself good with GOM, but there are so many things it can do I don't have time to learn them all.

I would love to not have 2 programs for each part. We identify the 70% as FP(first piece) and the 30% as IP(in process). Our title page probably doesn't need to identify which report it is, but it would be nice to include which it is...We use scripts with operator entry to pull the correct report so I could push a keyword into the title page with 'FP' or 'IP' if I had to.

Most importantly, I would love to use tags. If the operator clicks the FP button in the dialog, I would like it to output all the checks, and if they click the IP button, it outputs only those required checks.

Using a simple ellipse as an example....how would I make the FP program output both the major diameter and minor diameter, then with the IP report only output the major diameter without having 2 programs?

 

Much thanks for the help on this.

 

Link to comment
Share on other sites

Please sign in to view this username.

So I made some progress.

1) I highlighted two checks and hit 'T' for tag and named those 'FP' Then uncheck on of the checks and named that tag 'IP'

2) Seems you must click the little icon next to each tag to make a scene in the 3d view

3) Then I made two separate table report pages for each tag

My question now would be how if I present a checkbox to our operators with FP or IP how would I tell the export pdf function to only export pdf with the FP or IP tag?

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

import gom

print(gom.script.report.export_pdf.__doc__)


gom.script.report.export_pdf(
	export_all_reports=True,
	file='C:\test.pdf',
	jpeg_quality_in_percent=100)
report.export_pdf (PDF...) - Export As PDF

Parameters:

Name                    | Description                                                    | Type                                   | Optional
--------------------------------------------------------------------------------------------------------------------------------------------
reports                 | report pages to export                                         | Tom::MCADCmd::Traits::ElementSelection | Yes     
file                    | defines the file name of the PDF file                          | Tom::Parse::File                       | No      
jpeg_quality_in_percent | defines the quality of the JPEG compression in percent         | uint                                   | No      
max_dpi                 | defines the maximum dpi for the images in the document         | uint                                   | Yes     
export_all_reports      | defines if all or only the selected reports should be exported | bool                                   | Yes     

 

1.JPG

11.JPG

2.JPG

22.JPG

Link to comment
Share on other sites

Please sign in to view this username.

 couple of ways you can go from here .

The key thing in the end for control of export is the report pages .  They also can be tagged.

Tagging the inspection elements is maybe helpful in working with a big project.

Conditional if statement could be basic ( ignore syntax, just broad logic)

If dialogue =a

Export selected report pages ( record by selecting  the pages you want manually export pdf , then modify the code for directory)and

You coukd also decide to ' restore 3d view' from a captured table - export table

 

However , report page names/designations in code are not nice to handle.

because you can tag the report pages you can use this to make the container list of report pages you wish to export.

I hope this makes sense and keeps you going down a good road

This is def getting to a point where it would be nice to have shared screens to help explain..i just dont think this is possible anymore.  If you found me on linkedin feel free to drop me a dm and can have a think about practicalities ( im mainly thinking IP etc) 

Link to comment
Share on other sites

Please sign in to view this username.

I think I got something put together, but not sure it is the most efficient. I've created two Title pages as one needs to say FP and the other IP. Both are tagged with FP and IP respectively.

Then I have my report page with the FP outputs tagged with FP and the report page with IP outputs tagged with IP.  Below is my setup now and my code that seems to be working. Is this what you had in mind?

I would like to connect sometime. I'll get in touch soon.

 

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

import gom

FP_pages_list = []
IP_pages_list = []

for i in gom.ElementSelection ({'category': ['key', 'elements', 'explorer_category', 'reports']}):
	for y in i.tags:
		if y == 'FP':
			FP_pages_list.append(i)
		if y == 'IP':
			IP_pages_list.append(i)

print(FP_pages_list)
print(IP_pages_list)

gom.script.report.export_pdf (
	file='C:/Users/Owner/Documents/FP_report.pdf', 
	jpeg_quality_in_percent=100, 
	reports= FP_pages_list)

gom.script.report.export_pdf (
	file='C:/Users/Owner/Documents/IP_report.pdf', 
	jpeg_quality_in_percent=100, 
	reports= IP_pages_list)

 

FP_IP_one_program.JPG

Link to comment
Share on other sites

Yes! This type of approach is in line with what i had in mind 🙂 it keeps the coding level manageable and the project can be manipulated manually afterwards if needs be.  Printed out an ip report but needed a full one...no problem !

Technically the items in those report pages do not need to be tagged as well, but i think its good practice , simply as you can navigate the project easier 🙂

Link to comment
Share on other sites

Please sign in to view this username.

Glad you like the approach...the interesting thing about this thread is for me to globally update all our 100+ programs, I'm going to need the original python script I was pursuing at the beginning of this thread. That program opens the IP project and outputs the checks to a list which are saved and then can be activated in the main FP program to quickly make a IP separate report page. Turns out to update our entire programs I need both 😉

Now, I need to convince my manager to get on board. This is more work upfront, but much less on the back end.

On a separate note, I don't know how users of this amazing GOM software take advantage of all the benefits of the software. It is so complex that unless you know metrology, GDT, python, etc very well you will never get the most out of the software.

I'm on year 2 of my python coding so I would consider myself an early intermediate programmer, I'm fully versed on all the CT scanning metrics needed to get a good scan, my best skill in my opinion is in GDT and dimensional programming as I have a senior ASME cert in GDT, and I've pushed the envelope on prealignments to get stuff done in GOM that I don't think is normal with parts that are so long I use the top and bottom half and bounce b/w both halves with specific peralignments using surfaces applied with no measuring principle. 

To be great at the software it's like you have to know scanning, reporting, GDT, dimensioning, python, and be a bad ass troubleshooter as well. 

 

 

Link to comment
Share on other sites

Please sign in to view this username.

  im afraid i cant see a message or invite etc .  My profile pic atm is a 3dsl fringe pattern.  I should change it now i guess!

Link to comment
Share on other sites

 Share

×
×
  • Create New...