[SOLVED]Solid created by shell-faces-tollerance-sew has problem. Sew or Tollerance dosen't create solid?

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

[SOLVED]Solid created by shell-faces-tollerance-sew has problem. Sew or Tollerance dosen't create solid?

Post by mariwan »

My EdgeExtend supposed to create solid .. my code should create a solid but when I try with python to check it if it is solid .. it fails.

I upload the file and the picture of the code I used. And I checked even with defeaturing geometry check ...it should be ok. but it isn't.
bug in Part WB? or what?

what you see in the left is the answer of the defeaturing WB - geometry check. and in the right is the code i used to check but it says "Shell"

thanks in advance.
Attachments
test.JPG
test.JPG (206.8 KiB) Viewed 1259 times
test.FCStd
(5.31 KiB) Downloaded 11 times
Last edited by mariwan on Thu Dec 02, 2021 6:11 pm, edited 1 time in total.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Would you please let me know why it is wrong?

Post by openBrain »

Can confirm your object is a shell. Just "drill" it by cutting a box or cylinder and you'll see. ;)

Maybe it comes from the way you create it, but hard to say without any more clue.
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Would you please let me know why it is wrong?

Post by mariwan »

openBrain wrote: Thu Dec 02, 2021 4:50 pm Can confirm your object is a shell. Just "drill" it by cutting a box or cylinder and you'll see. ;)

Maybe it comes from the way you create it, but hard to say without any more clue.

Code: Select all

            soldObjShape = _part.Solid(_part.Shell(_resultFace))
            newObj = App.ActiveDocument.addObject("Part::Feature","comp")
            newObj.Shape = soldObjShape
            newObj = self.sewShape(newObj)
            newObj = self.setTolerance(newObj)
            for face in self.newFaces:
                App.ActiveDocument.removeObject(face.Name)
that is the code. I use Part.Solid.. Shouldn't that create a solid? I took it from the FreeCAD wiki
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Would you please let me know why it is wrong?

Post by openBrain »

mariwan wrote: Thu Dec 02, 2021 4:53 pm that is the code. I use Part.Solid.. Shouldn't that create a solid? I took it from the FreeCAD wiki
Those 2 lines don't make much sense ATM as they are redefining your 'newObj' variable with some functions that I don't see (don't know type of 'self' and if functions are native or custom).

Code: Select all

            newObj = self.sewShape(newObj)
            newObj = self.setTolerance(newObj)
Anyway if I do in your example file

Code: Select all

Part.show(Part.Solid(App.ActiveDocument.Solid.Shape))
everything is fine and I get a solid. So I think the problem isn't in FreeCAD. ;)

BTW : Defeaturing tells you "Solid" because it is the name of the object, not because it is an actual solid. ;)
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Would you please let me know why it is wrong?

Post by mariwan »

Code: Select all

def setTolerance(self, sel):
        try:
            if hasattr(sel, 'Shape'):
                ns = sel.Shape.copy()
                new_tol = 0.001
                ns.fixTolerance(new_tol)
                sel.ViewObject.Visibility = False
                sl = App.ActiveDocument.addObject("Part::Feature", "Solid")
                sl.Shape = ns
                g = Gui.ActiveDocument.getObject(sel.Name)
                g.ShapeColor =   sel.ViewObject.ShapeColor
                g.LineColor =    sel.ViewObject.LineColor
                g.PointColor =   sel.ViewObject.PointColor
                g.DiffuseColor = sel.ViewObject.DiffuseColor
                g.Transparency = sel.ViewObject.Transparency
                App.ActiveDocument.removeObject(sel.Name)
                sl.Label = 'Extended'
                return sel
        
        except Exception as err:
            App.Console.PrintError("'sewShape' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)

    # Based on the sewShape from De-featuring WB,
    # but simplified- Thanks for the author

    def sewShape(self, sel):
        """[Fix issues might be in the created object]

        Args:
            sel ([3D Object]): [Final object that needs repair.
                                Always new object creates as result of sew]
        """
        try:
            if hasattr(sel, 'Shape'):
                sh = sel.Shape.copy()
                sh.sewShape()
                sl = App.ActiveDocument.addObject("Part::Feature", "compSolid")
                sl.Shape = sh

                g = Gui.ActiveDocument.getObject(sl.Name)
                g.ShapeColor = Gui.ActiveDocument.getObject(sel.Name).ShapeColor
                g.LineColor =  Gui.ActiveDocument.getObject(sel.Name).LineColor
                g.PointColor = Gui.ActiveDocument.getObject(sel.Name).PointColor
                g.DiffuseColor = Gui.ActiveDocument.getObject(
                    sel.Name).DiffuseColor
                g.Transparency = Gui.ActiveDocument.getObject(
                    sel.Name).Transparency
                App.ActiveDocument.removeObject(sel.Name)
                App.ActiveDocument.recompute()
                return (sl)
            
        except Exception as err:
            App.Console.PrintError("'sewShape' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
These are faces that I convert them to shell -->solid --> fix tollerance --> sew

I tested in Part WB the tool - >Make Solid .. it convert it to solid .. but I do the same sequence that tool tells me.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Would you please let me know why it is wrong?

Post by openBrain »

IMO, setTolerance returns 'sel' instead of 'sl'.
User avatar
Shalmeneser
Veteran
Posts: 9545
Joined: Wed Dec 23, 2020 12:04 am
Location: Fr

Re: Would you please let me know why it is wrong?

Post by Shalmeneser »

Could you choose more specific title for your post, please ?
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Would you please let me know why it is wrong?

Post by mariwan »

openBrain wrote: Thu Dec 02, 2021 5:16 pm IMO, setTolerance returns 'sel' instead of 'sl'.
:oops:
Yes you are right.
But for fixing the solid problem .. I needed to recreate a solid object again. Seems that sew or tolerance shapes are not solid. Regarding the Defeature.. I was not clear but I used the checking function for solid .. so it was telling me that it was ok .. you can try it.

Here my final code which works.

Code: Select all

    def recreateObject(self):
        # FIXME:
        # Here we have 
        # We try to create a wire-closed to replace the sides we delete.
        # This will be way to complex . with many bugs :(
        try:
            App.ActiveDocument.removeObject(self.newEdge.Name)
            _result = []
            _resultFace=[]
            _result.clear()
            for faceVert in self.savedVertices:
                convert = []
                for vert in faceVert:
                    convert.append(vert.Point)
                _Newvertices = convert
                newPolygon = _part.makePolygon(_Newvertices, True)
                convert.clear()
                newFace = _part.makeFilledFace(newPolygon.Edges)
                if newFace.isNull():
                    raise RuntimeError('Failed to create face')
                nFace = App.ActiveDocument.addObject("Part::Feature", "nFace")
                nFace.Shape = newFace
                _result.append(nFace)
                _resultFace.append(newFace)
            self.newFaces = _result
                        
            solidObjShape = _part.Solid(_part.Shell(_resultFace))
            newObj = App.ActiveDocument.addObject("Part::Feature", "comp")
            newObj.Shape = solidObjShape
            newObj = self.sewShape(newObj)
            newObj = self.setTolerance(newObj)
            solidObjShape = _part.Solid(newObj.Shape)
            final = App.ActiveDocument.addObject("Part::Feature", "Extended")
            final.Shape = solidObjShape
            App.ActiveDocument.removeObject(newObj.Name)
            for face in self.newFaces:
                App.ActiveDocument.removeObject(face.Name)

        except Exception as err:
            App.Console.PrintError("'recreate Object' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
thank you for pointing out the problem.

Note:
Unfortunately, Part.Show doesn't return the created object. Which is a big problem .. You cannot use it in python. How can you find the created object? it is impossible if you think general.
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Would you please let me know why it is wrong?

Post by mariwan »

Shalmeneser wrote: Thu Dec 02, 2021 5:35 pm Could you choose more specific title for your post, please ?
sorry, you see it became a long title.
User avatar
Shalmeneser
Veteran
Posts: 9545
Joined: Wed Dec 23, 2020 12:04 am
Location: Fr

Re: Would you please let me know why it is wrong?

Post by Shalmeneser »

mariwan wrote: Thu Dec 02, 2021 6:11 pm sorry, you see it became a long title.
No problem. It will be better for memory and future research.
Post Reply