14 Replies Latest reply on Nov 23, 2017 5:12 AM by Rob Edwards

    How to get 3D printed geometry from gcode (self intersecting)

    Sander Voss

      Scenario:

       

      In order to get more accurate FEA for 3D printed parts I want to get the model as it is printed by the printer, so the sliced part with the printed layers and the infill etc.

      I have written a macro that allows me to import a .txt with the points of the extruder head and draw lines in between them.

       

      However, when wanting to sweep along this line it cannot be performed due to self intersecting geometry. However, this self intersection is wanted as during the printing the layers merge together to form the part.

       

      There is a similar question on this forum but I found it not entirely fitting my problem (https://forum.solidworks.com/message/657184?q=Intentionally%20self%20intersecting ). The weldment method works fairly okay, however it creates very sharp geometry. I could go about and fillet those but as there will be hundreds and hundreds of these corners I am looking for a better solution and am currently lost for options.

       

      Note that the extruded profile is roughly a circle with a diameter of +/- 45-50mm. I have added the part file as an attachment.

       

      Thank you for taking a look at this!

       

      Capture.PNG

       

      Added the .txt files for the tool paths. One is comma separated and the other is tab separated.

        • Re: How to get 3D printed geometry from gcode (self intersecting)
          Alex Burnett

          While I can't open your file (I'm running 2016 still), I do see why there is likely an issue here. If you're sweeping a profile and get to a sharp turn, the profile tries to stay normal to the path. The areas where there is a tangent to the path basically reversing on itself causes the profile to essentially make a 180 degree twist and then reverse direction causing self intersecting geometry. Another thing to look out for is a very small radius in a turn causing the profile to turn back in on itself. I'm not sure if much of that makes sense but it's why SW is not happy sweeping this sort of curve.

           

          Your result may be able to be achieved with some work and multiple sweeps and then combine into a solid. I'm not sure what else to suggest.

          • Re: How to get 3D printed geometry from gcode (self intersecting)
            Rob Edwards

            Hi Sander

            This may be a crazy idea, but as you can write macros, what about letting the macro create lots of separate features for you.

            This could be simple extrudes, or here I tried using negative space and then combine subtracting at the end.

             

            This is a section view..

             

            finished result

              • Re: How to get 3D printed geometry from gcode (self intersecting)
                Sander Voss

                Hi Rob,

                 

                Wow that result looks exactly like what I need!

                I have very little experience with VBA and SW macros but I will start trying to figure out how to build a macro around this.

                Would you have any ideas to point me into the right direction?

                 

                Thanks so much

                  • Re: How to get 3D printed geometry from gcode (self intersecting)
                    Rob Edwards

                    Hi Sander

                    I too have little experience of writing macros, but am wanting to learn.  In the past I have managed to codge together a couple by macro recording, googling, code snipping, etc.  There are many macro magicians on the forum who i'm sure would help, if you ask in the right place.

                    Do you have an example text file?  Also you say the extrude profile is roughly a circle, can you post the actual profile you require?

                      • Re: How to get 3D printed geometry from gcode (self intersecting)
                        Sander Voss

                        Hi Rob,

                        Yes that is what I am attempting to do now as well. However, I am still struggling to use your method on one of my profiles. I have added the files to my original post, one folder with comma separated files and one with tab separated files.

                         

                        For the profile, I am not exactly sure yet what will work best. I was going to change the shape depending on the FEA results until I got close to the real stress tests that I performed. For the first try I was thinking of a straight slot of height 0.2mm and width 0.67mm.

                          • Re: How to get 3D printed geometry from gcode (self intersecting)
                            Rob Edwards

                            Hi Sander

                            Can you recommend which of the archived files to use for a test.  I opened the first one and got this array of points

                              • Re: How to get 3D printed geometry from gcode (self intersecting)
                                Sander Voss

                                I have written a macro that imports a .txt and creates a line through them, I use the csv files with this macro. 1_11.txt is one of the trickiest files. It is just very frustrating that there is no easy way of getting the solid geometry of a part exactly as it is 3D printed. I attached the macro to this message

                                  • Re: How to get 3D printed geometry from gcode (self intersecting)
                                    Rob Edwards

                                    Here we go, hows this?

                                    I didn't code the revolve, extrudes or combine

                                     

                                     

                                    Dim swApp As Object

                                    Sub main()

                                     

                                    Set swApp = Application.SldWorks

                                    Set Part = swApp.ActiveDoc

                                     

                                    swApp.ActiveDoc.ActiveView.FrameState = 1

                                     

                                    Open "C:\Users\369\Desktop\PointData.txt" For Input As #1

                                     

                                     

                                    Dim myFeature As Object

                                     

                                     

                                    Dim count As Long

                                     

                                     

                                    Dim BodyName As String

                                    Dim SketchName As String

                                     

                                     

                                     

                                     

                                    Dim boolstatus As Boolean

                                     

                                     

                                     

                                     

                                    Dim skLine As Object

                                     

                                     

                                    Dim first As Boolean

                                    first = True

                                    count = 0

                                     

                                     

                                    Do While Not EOF(1)

                                      

                                        Input #1, X1, Y1, Z1

                                     

                                     

                                        If first Then

                                            first = False

                                        Else

                                            boolstatus = Part.Extension.SelectByID2("Revolve1", "SOLIDBODY", 0, 0, 0, False, 1, Nothing, 0)

                                            Set myFeature = Part.FeatureManager.InsertMoveCopyBody2(X1, Y1, Z1, 0, 0, 0, 0, 0, 0, 0, True, 1)

                                            

                                            Part.ClearSelection2 True

                                            Part.SketchManager.Insert3DSketch True

                                            Set skLine = Part.SketchManager.CreateLine(X1, Y1, Z1, X2, Y2, Z2)

                                            Part.SketchManager.InsertSketch True

                                           

                                           

                                            BodyName = "Body-Move/Copy" & count

                                            SketchName = "3DSketch" & count

                                           

                                            boolstatus = Part.Extension.SelectByID2(BodyName, "SOLIDBODY", 0, 0, 0, False, 1, Nothing, 0)

                                            boolstatus = Part.Extension.SelectByID2(SketchName, "SKETCH", 0, 0, 0, True, 4, Nothing, 0)

                                                 

                                            Set myFeature = Part.FeatureManager.InsertCutSwept4(False, _

                                                                                                False, _

                                                                                                0, _

                                                                                                False, _

                                                                                                False, _

                                                                                                1, _

                                                                                                1, _

                                                                                                False, _

                                                                                                0, _

                                                                                                0, _

                                                                                                0, _

                                                                                                0, _

                                                                                                False, _

                                                                                                True, _

                                                                                                0, _

                                                                                                True, _

                                                                                                True, _

                                                                                                True, _

                                                                                                False)

                                     

                                     

                                        End If

                                           

                                        X2 = X1

                                        Y2 = Y1

                                        Z2 = Z1

                                        count = count + 1

                                       

                                    Part.ClearSelection2 True

                                     

                                     

                                       

                                       

                                    Loop

                                    Close #1

                                     

                                     

                                     

                                    End Sub

                                      • Re: How to get 3D printed geometry from gcode (self intersecting)
                                        Sander Voss

                                        Wow that looks absolutely solid! So you first did the revolve and created the block like you did in the previous example and then ran the script? I will take a look at this later today but it looks very promising, thank you SO much! I will post back on my results.

                                          • Re: How to get 3D printed geometry from gcode (self intersecting)
                                            Rob Edwards

                                            Morning Sander

                                             

                                            I know there's a few potential problems with it, but it was getting late and I wanted to post something. 

                                            It's good fun writing macros, but my knowledge of the API and VBA is sooo bad, it takes me ages and I don't really understand much.

                                             

                                            I couldn't figure out how to Select a body for the scope of the sweep, so this cuts through All bodies.. could be a problem if a point is near the origin, where the revolve body is.

                                             

                                            The scale is all wrong, at first when I tried dividing everything by 1000 the sweep failed, so I just did it larger.  I'm not sure what was causing that problem.  It may have been something else, thats fixed now

                                             

                                            I'd like to do more work on it, but not sure when I'll get the time

                                             

                                            I would probably make a new part that has just the revolve in it.

                                             

                                            I would then make a new part template that consists of the revolve part inserted, then get the macro to create a new part using that template... 

                                             

                                            Oh and you'd want to get it open all the text files and create all the parts...  there's plenty more work to do, but I'm happy to have a working proof of concept.

                                             

                                            All the best

                                              • Re: How to get 3D printed geometry from gcode (self intersecting)
                                                Sander Voss

                                                Morning Rob

                                                 

                                                Thanks again for spending time on this! Yes it can be quite confusing indeed. I believe in order to select a body one should first have to select the feature from the tree and then getspecific feature or something like that. I used it in my weldment attempt to select a certrain sketch:

                                                boolstatus = Part.Extension.SelectByID2(currentSketchName, "SKETCH", 0, 0, 0, False, 0, Nothing, 0) 'Select Sketch

                                                Set swFeat = Part.SelectionManager.GetSelectedObject6(1, 0) 'Get the selected object and store in the swFeature

                                                Set swSketch = swFeat.GetSpecificFeature2   'Get the sketch feature from the swFeature

                                                 

                                                I think if we can manage to get this to work for one layer, upscaling would not have to be too difficult. I already achieved this when I was trying the weldment method, only because they were weldments I ended up with a useless part, plus it was so slow that it would make solidworks crash.