22 Replies Latest reply on Jun 25, 2017 1:55 PM by Viktor Ács

    What can i use to select instead of booleanstatus?

    Viktor Ács

      Hi,

      i'm new to APIs and I'm curious what can you use instead of booleanstatus to select something. For example, i have selected a line with cursor and i get my object with this line: selMgr.GetSelectedObject6(i, -1)

      Then i recorded a macro to convert lines and i got this:

      boolstatus = Part.Extension.SelectByID2("Line1@3DSketch47", "EXTSKETCHSEGMENT", -6.24001922330137E-02, 0.186067950480265, 0, False, 0, Nothing, 0)

      boolstatus = Part.SketchManager.SketchUseEdge3(False, False)

      Is boolstatus a variable? why do i save my selection then my convert command in it, looks so silly. i'm not judging i just really dont understand. anyway here is what i want to do:

              swModel.SketchManager.Insert3DSketch True      

          For i = 1 To selMgr.GetSelectedObjectCount

              If selMgr.GetSelectedObjectType3(i, -1) = 24 Then

      'select the lines for convert

                  boolstatus = selMgr.GetSelectedObject6(i, -1)

      'convert the selected line

                  boolstatus = swModel.SketchManager.SketchUseEdge3 False, False

                  swModel.ClearSelection2 True

              End If

          Next i

      Thx for any answers.

        • Re: What can i use to select instead of booleanstatus?
          Christian Chu

          It's just a boolean variable for true/false (such as go/no go or do/don't) and the simplest way to execute your statement - you can make your own but it's way more complicated

          • Re: What can i use to select instead of booleanstatus?
            John Alexander

            I normally use the following pattern if i care what the return value was but don't want to store boolstatus.

             

            if functionThatReturnsBoolean then

                 do something based on the fact that it was successful

            else

                 do something based on the fact that it wasn't successful

            end if

             

            Alternatively,

             

            boolstatus = functionThatReturnsBoolean: Debug.assert boolstatus

             

            Will throw an error at that line when false is returned. This a good pattern when debugging.

            • Re: What can i use to select instead of booleanstatus?
              Viktor Ács

              i forgot to mention the code i pasted in doesnt work, and thanks for the infos but i still cant figoure out how i supposed to select my selMgr.GetSelectedObject6(i, -1) and execute the swModel.SketchManager.SketchUseEdge3 False, False on it. Please can u help me out on this? Keep in mind im really new to this, i study this kind of stuff for a week, and have no idea where is the execute part.

                • Re: What can i use to select instead of booleanstatus?
                  Christian Chu

                  Before you go any further, I recommend you get some basic knowledge of  Visual Basic (go to your local library and find some VB6 books - folks there might give you free books - or learn online)  - trial and error is not a good way to learn programming SW API - you can get it work now, but might get trouble again when you add  next lines

                    • Re: What can i use to select instead of booleanstatus?
                      Viktor Ács

                      I have deadline on this, sure i could research for weeks from books, after i finished this 2 line command. Only if anyone can help me with it. You wont find this kind of basic knowledge on the internet,but only in basic knowledge tutorial samples but then again i have a deadline,

                        • Re: What can i use to select instead of booleanstatus?
                          Christian Chu

                          What kind of project's deadline with a macro while you can manually edit the sketch and change

                          By the way, I don't even know clearly what you want from the code you posted and don't have a file with specific sketch name ?

                            • Re: What can i use to select instead of booleanstatus?
                              Viktor Ács

                              My problem is i want to avoid using specific names, i can select my lines with the code:

                              For i = 1 To selMgr.GetSelectedObjectCount

                                      If selMgr.GetSelectedObjectType3(i, -1) = 24 Then

                              and i get my lines in this row: selMgr.GetSelectedObject6(i, -1)

                              and this is the row i want to execute on every selected i object:

                              swModel.SketchManager.SketchUseEdge3 False, False

                              but i dont know how to do it since the recorded macro shows me to save it in the boolean variable but this dowent work:

                                          boolstatus = selMgr.GetSelectedObject6(i, -1)

                                          boolstatus = swModel.SketchManager.SketchUseEdge3 False, False

                              My question is how can i combine the 2 row in a code, that is working.

                                • Re: What can i use to select instead of booleanstatus?
                                  Peter Brinkhuis

                                  Christian Chu has a point here, we're not sure what you are trying to do. We need answers to the following questions:

                                  1. What do you do before the macro is run? Do you select sketch items?
                                  2. What should the macro do?
                                  3. What should be the end result?

                                   

                                  Forget the code for a moment. Just explain it in text.

                                   

                                  Also, have a look in the help. It's massive and pretty complete. Here is the help file on the GetSelectedObjects for example.

                                   

                                  2015 SOLIDWORKS API Help - GetSelectedObject6 Method (ISelectionMgr)

                                   

                                  You'll see that the return value, the one before the equal sign, is of type 'object'. Not of type boolean. You should really know the difference, these are the true basics of programming. 'boolstatus' is just a name for a variable that SolidWorks chose to use in recorded macros for a return value of a function that is of type boolean. If you're trying to get the selected object, you better use an object type as the return value. If you are really sure, you could for example use a SketchLine instead of an object. Better would be to find the type of the object and if that is correct, set a SketchLine (or SketchPoint or something else, I don't know what you want) equal to the object.

                                    • Re: What can i use to select instead of booleanstatus?
                                      Viktor Ács

                                      I think i expressed myself badly, I understand whats a boolean, thats why i dont understand why this works:

                                      boolstatus = Part.SketchManager.SketchUseEdge3(False, False)

                                      But lets put aside this part, becous i can learn about it from tutorials.

                                      1. Before the macro, i select some sketch lines.

                                      2. I want the macro to convert the lines in my sketch, wich the macro creates with swModel.SketchManager.Insert3DSketch True

                                      3. The result should be sketch with lines/edges which are converted with the Part.SketchManager.SketchUseEdge3(False, False)

                                       

                                      I tought its the simplest thing in creating macros, but i cant find any help. I dont even understand what i dont understand, so its hard to look it up myself, i tought if you give me the solution for this simple code, i would imdietly see what am i missing. My point is for use SketchUseEdge3 i need to have sketchsegments selected, how do i select them, well i know i can select them with selMgr.GetSelectedObject6(i, -1) but this gives me an object. So how do i select this object for convert?

                          • Re: What can i use to select instead of booleanstatus?
                            Solid Air

                            I agree with others that you should take some time and get some training on creating SolidWorks macros.  I also suggest you take some time and look at the SolidWorks API help.  Example: the function selMgr.GetSelectedObject6(i, -1) does not return boolstatus, it returns an object.

                             

                            It appears you have already selected the edges you want to convert.  In that case you do not need this function at all.  The code below will convert selected edges to sketch lines in a 3D sketch.  You will notice I did not use boolstatus.  As part of your training, I will let you figure out the why.

                             

                            Dim swApp As SldWorks.SldWorks

                            Dim swModel As SldWorks.ModelDoc2

                             

                            Sub main()

                             

                                Set swApp = Application.SldWorks

                                Set swModel = swApp.ActiveDoc

                               

                                swModel.SketchManager.Insert3DSketch True

                               

                                swModel.SketchManager.SketchUseEdge3 False, False

                               

                                swModel.SketchManager.InsertSketch True

                                swModel.ClearSelection2 True

                               

                            End Sub

                              • Re: What can i use to select instead of booleanstatus?
                                Viktor Ács

                                We are running in circles, as i asked originally, i want to select my object for use sketchuseedge3. I figured it out myself already that you can use swModel.SketchManager.SketchUseEdge3 False, False, when you already selected the line, or you can use

                                boolstatus = Part.Extension.SelectByID2("Line1@3DSketch47", "EXTSKETCHSEGMENT", -6.24001922330137E-02, 0.186067950480265, 0, False, 0, Nothing, 0)

                                boolstatus = Part.SketchManager.SketchUseEdge3(False, False)

                                when you know the line name. All i want to achieve is apply the swModel.SketchManager.SketchUseEdge3 False, False on my object selMgr.GetSelectedObject6(0, -1).  I want to apply on every second or third line which i can acheive like this selMgr.GetSelectedObject6(i*2(or 3), -1) but i dont know how to select it, its an object i get it, i guess you can select objects, but how? Thats my question

                                What can i use to select instead of booleanstatus?

                                  • Re: What can i use to select instead of booleanstatus?
                                    Solid Air

                                    Viktor,

                                     

                                    How are the objects selected that you want to use the GetSelectedObjects6 call on?  If you have preselected your lines then you will need to deselect the ones you do not want to convert.

                                     

                                    Can you provide an example?

                                      • Re: What can i use to select instead of booleanstatus?
                                        Viktor Ács

                                        How do you deselect/select an object?

                                          • Re: What can i use to select instead of booleanstatus?
                                            Solid Air

                                            There are multiple ways to select; it all depends on what you are trying to select.  Besides the clearselections call I found a deselect call based on index.  There may be more however (I am not on my SW computer at the moment).  To answer your question you really need to provide exactly what you are out to accomplish.  I thought I understood before but you did not like the code I provided.

                                              • Re: What can i use to select instead of booleanstatus?
                                                Viktor Ács

                                                I'm tring to be not salty, but its not really easy, i want to select an object, so i can execute stuff on it. Correct me if i'm wrong but to execute

                                                swModel.SketchManager.SketchUseEdge3 False, False

                                                you have to have something selected, right? but how do you select it with raw code. Im asking this the fourth times. All i know is i want to select an object from an array, which i can create with preselecting everything then use

                                                selMgr.GetSelectedObject6(i, -1).

                                                  • Re: What can i use to select instead of booleanstatus?
                                                    Solid Air

                                                    Viktor

                                                     

                                                    It was certainly not my intent to upset you.  This post started out with you asking about boolstatus (which you were applying incorrectly to the GetSelectedObject6 call).  Later after being pressed by others to explain what you were trying to do you posted:

                                                     

                                                    1. Before the macro, i select some sketch lines.

                                                    2. I want the macro to convert the lines in my sketch, wich the macro creates with swModel.SketchManager.Insert3DSketch True

                                                    3. The result should be sketch with lines/edges which are converted with the Part.SketchManager.SketchUseEdge3(False, False)

                                                     

                                                    To me this meant you were preselecting the lines before running the macro.  In this case you do not need any select calls because you already have what you want selected!  So I replied with:

                                                     

                                                    Dim swApp As SldWorks.SldWorks

                                                    Dim swModel As SldWorks.ModelDoc2

                                                     

                                                    Sub main()

                                                     

                                                        Set swApp = Application.SldWorks

                                                        Set swModel = swApp.ActiveDoc

                                                     

                                                        swModel.SketchManager.Insert3DSketch True

                                                     

                                                        swModel.SketchManager.SketchUseEdge3 False, False

                                                     

                                                        swModel.SketchManager.InsertSketch True

                                                        swModel.ClearSelection2 True

                                                     

                                                    End Sub

                                                     

                                                    This code works with preselected lines/edges (did you ever run the code?).

                                                     

                                                    You then stated that you did not want to convert every selected line but every other or every third.  I was vague with my answer because I wanted you to learn to use the API help.  The call I was hoping you would find is SelectionMgr.DeSelect2 (ByVal AtIndex as variant, ByVal Mark as Long) as LongI suppose you did not appreciate me being vague because you are on a deadline but it takes more than a couple weeks for a person to learn SolidWorks API calls (at least it did you me).

                                                     

                                                    I am just as frustrated as you because I still do not know what you want to do.  You have changed the spec of what you want at least three times the way I read your posts.

                                                     

                                                    Finally, I am sorry I was not able to help you.

                                                      • Re: What can i use to select instead of booleanstatus?
                                                        Viktor Ács

                                                        Dont take it personal, i'm sure i could get the answer in a minute with a personal talk, but on forums its much harder to explain myself, especially english isnt my first language. I'm just mildly salty because im over the deadline and have other projects to do, and the answer i was looking for was so simple. Sorry for being salty i understand its not apropiate on a forum.

                                                    • Re: What can i use to select instead of booleanstatus?
                                                      Dave Bear

                                                      Just can't please some people Solid!

                                                       

                                                      Dave.

                                                        • Re: What can i use to select instead of booleanstatus?
                                                          Viktor Ács

                                                          Yeah, it's a big suprise you can't please someone by avoiding the answer. It took me 3 day and 20 post in the forum to figure out you can select stuff with

                                                          entity.Select True

                                                          yeah thank you very much, telling me to learn the basics was really useful because you just couldnt answer the question WHAT CAN I USE TO SELECT. Big suprise its entity.Select True

                                                          When i wrote the title i knew it will be something as simple as this. Thats why im so mad i had to waste 3 day on this. how can i select stuff, oh its easy you just use the command entity.Select True. why was it so hard? at lest explain that.

                                              • Re: What can i use to select instead of booleanstatus?
                                                Roland Schwarz

                                                Sound like a good job for a paid consultant. Not me. Someone else. I stopped doing it because people never pay.