Showing results for 
Search instead for 
Do you mean 
Reply

Facetid/Model tag in Python

[ Edited ]

In the NX Open API (for Python), how would you obtain the model <tag> and facetid for an imported STL file/faceted model? I am trying to run various STL/Facet methods in Python

NXOpen.UF.Facet.AskPlaneEquation(model, facetid)
NXOpen.UF.Facet.CycleFacets(model, facetid)


 

I referred to the following documentation documentation but did not find an example

https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/nxopen_pyt...

 

https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/ugopen_doc...

 

For solid bodies, I typically use this Python code to find the journal identifier 

for body in workPart.Bodies:
        self.theLw.Open()
        self.theLw.WriteLine("Solid body name is" + body.JournalIdentifier)
        mybodieslist.append(body.JournalIdentifier)

as a workaround, I recorded (in python) the "Fill hole" command and obtained the Entity name and then used that to obtain the tag. See code below. How could I do this without knowing the entity name before hand?

 

 

facet_body = workPart.FacetedBodies.FindObject("ENTITY 139 1 1")

 

 

10 REPLIES

Re: Facetid/Model tag

Similar to a .Bodies collection, a part object has a .FacetedBodies collection.

 

If there is only one facet body in the part file, getting a reference to it is easy - it's the only one in the collection. If your part has multiple facet bodies, you will need to devise a way to tell them apart.

Re: Facetid/Model tag

This is what I have so far. I get an error when trying to call the NXOpen.UF.Facet.AskNFacetsInModel method. It states that no argument is being passed when I am passing uf_facet. See attached pic.

       global facet_tag, workPart, uf_tag
        workPart = self.theSession.Parts.Work
        for facet_body in workPart.FacetedBodies:
            self.theLw.WriteLine("Facet Journal id is " + facet_body.JournalIdentifier)
            self.theLw.WriteLine("Tagged object is " + str(NXOpen.TaggedObject(facet_body)))
            facet_tag= NXOpen.TaggedObject(facet_body)
            self.theLw.WriteLine("Tag property is " + str(facet_tag.Tag))
            self.theLw.WriteLine("UF tag is " + str(NXOpen.UF.Tag(facet_body)))
            uf_tag= NXOpen.UF.Tag(facet_body)
            
            uf_facet=NXOpen.UF.Facet(facet_body)
            self.theLw.WriteLine("UF facet is " + str(uf_facet))
            NXOpen.UF.Facet.AskNFacetsInModel(uf_facet)

Re: Facetid/Model tag

facet_tag= NXOpen.TaggedObject(facet_body)

I don't think the line above is doing what you think it's doing.

 

If you want the tag of the facet_body, wouldn't it just be facet_body.tag?

Re: Facetid/Model tag


cowski1 wrote:
facet_tag= NXOpen.TaggedObject(facet_body)

I don't think the line above is doing what you think it's doing.

 

If you want the tag of the facet_body, wouldn't it just be facet_body.tag?


When I write 

 

NXOpen.TaggedObject(facet_body.tag)

I get the error message "NXOpen.Facet.FacetedBody object has no attribute 'tag' "

 

The code below seems to work.

 

uf_tag= NXOpen.UF.Tag(facet_body)
self.theLw.WriteLine("UF tag is " + str(uf_tag))

How could I obtain all the facet_id's of my imported STL file? The NXOpen.UF.Facet.CycleFacets method requires a facet_it

Re: Facetid/Model tag

"When I write 

 

NXOpen.TaggedObject(facet_body.tag)

I get the error message "NXOpen.Facet.FacetedBody object has no attribute 'tag' "

 

 

Then don't write that - because it is wrong. The code:

NXOpen.TaggedObject() will initialize a new tagged object. This is not what you want to do; if you have a reference to an existing facet body, you already have a tagged object. An existing facet body will have a 'tag' property: refer to

 

https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/nxopen_pyt...

Re: Facetid/Model tag

[ Edited ]

Thanks for the follow up. I did not see your reply when I wrote the post below. For the UF.Facet class, how could I obtain the model tag and the facet id? 

https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/nxopen_pyt...

 

Just found the documentation I needed, NXOpen.Facet.FacetedBody class. I was looking through the UF.Facet class documentation. 

 

https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/nxopen_pyt...

 

A tag would simply be 

NXOpen.Facet.FacetedBody.Tag

for facet_body in workPart.FacetedBodies:
          self.theLw.WriteLine("Facet tag is " + str(facet_body.Tag))

 

Re: Facetid/Model tag

[ Edited ]
        self.theLw.WriteLine(str(NXOpen.UF.Facet()))
        uf_facet=NXOpen.UF.Facet()
        self.theLw.WriteLine("This is the UF.facet object "+str(uf_facet))

#still trying to figure out these arguments
NXOpen.UF.Facet.AskPlaneEquation(model, facet_id)

going through this

https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/ugopen_doc...

Re: Facetid/Model tag

got both the UF.Facet class and the NXOpen.Facet.FacetedBody to work properly. Code 

Is there a way for the community to submit examples/corrections to the online Python documentation?

global facet_tag, workPart, facet_id, levelofdetail, num_facets
        workPart = self.theSession.Parts.Work

        

        for facet_body in workPart.FacetedBodies:
            self.theLw.WriteLine("Facet is " + facet_body.JournalIdentifier)
            facet_id=facet_body.JournalIdentifier
            facet_tag=facet_body.Tag
            self.theLw.WriteLine("Facet tag is " + str(facet_tag))
            
            self.theLw.WriteLine("Level of detail is " + str(facet_body.NumberOfLevelsOfDetail))
            levelofdetail=facet_body.NumberOfLevelsOfDetail
            
            self.theLw.WriteLine("Parameters is " + str(facet_body.GetParameters()))
            self.theLw.WriteLine("Is this a Solid Body? " + str(facet_body.IsSolidBody))
            #facet_body.GetNumberOfEdges()
            self.theLw.WriteLine("")

        
        self.theLw.WriteLine(str(NXOpen.UF.Facet()))
        uf_facet=NXOpen.UF.Facet()
        uf_facet.AskDefaultParameters()
        self.theLw.WriteLine("This is the facet object "+str(uf_facet))
        self.theLw.WriteLine("Default Parameters are" + str(uf_facet.AskDefaultParameters()))
        self.theLw.WriteLine("# of facets are " + str(uf_facet.AskNFacetsInModel(facet_tag)))

Re: Facetid/Model tag

"Is there a way for the community to submit examples/corrections to the online Python documentation?"

 

Yes. Log an incident report (IR) with GTAC. I'm not sure that they will make use of your example code, but they will correct any known mistakes in the documentation.