4 Replies Latest reply on Apr 28, 2014 9:57 PM by Mariah Sharp

    Picture handling macro in drawing - Help plz

    Tibor Meszes

      Hi,

       

      I've to add a barcode picture to the drawings, so I have a simple macro for that, that works fine.

      My problem is: if the drawing changes, before I inster a new barcode, I have to delete the previous, but I don't know the object name, because on every "InsertSketchPicture" the object name counter will rise (Sketch Picture1, Sketch Picture2, etc).

       

      One solution if I rename the inserted picture, but I don't know how can I do this. Can I rename somehow the inserted picture's object?

      Ant thats it, I don't know other solution, but if somebody has any idea, please share that with me.

       

      my code part is:

      Set swApp = Application.SldWorks

      Set Part = swApp.ActiveDoc

      .....

      Part.EditTemplate

      Set SkPicture = Part.SketchManager.InsertSketchPicture("C:\barcode.png")

      SkPicture.SetOrigin 0.0128, 0.0052

      SkPicture.SetOrigin 0.13, 0.0052

      SkPicture.SetSize 60 / 1000, 9 / 1000, True

      Part.EditSheet

      ...

       

      thank you

        • Re: Picture handling macro in drawing - Help plz
          Simon Turner

          How about getting all sketch pictures in the drawing and checking GetOrigin on each one to find the one closest to where you would have inserted it?

          • Re: Picture handling macro in drawing - Help plz
            Matt Martens

            Set SkPicture = Part.SketchManager.InsertSketchPicture("C:\barcode.png")

            SkPicture.GetFeature.Name = "Name of Sketch Picture"

            SkPicture.SetOrigin 0.0128, 0.0052

            SkPicture.SetOrigin 0.13, 0.0052

            SkPicture.SetSize 60 / 1000, 9 / 1000, True

            Part.EditSheet

            ...

             

            This line of code should rename the sketch picture to whatever you want it to be. Make sure the name is in quotes or set a string variable to the name. I would recommend the string variable because you can use it to find the sketch picture to delete before inserting a new one and renaming it.

            • Re: Picture handling macro in drawing - Help plz
              Tibor Meszes

              Thank all of you the fast answers, Matt's solution is perfect for me

              • Re: Picture handling macro in drawing - Help plz
                Mariah Sharp

                Tibor Meszes wrote:

                 

                Hi,

                 

                I've to add a barcode picture to the drawings, so I have a simple macro for that, that works fine.

                My problem is: if the drawing changes, before I inster a new barcode, I have to delete the previous, but I don't know the object name, because on every "InsertSketchPicture" the object name counter will rise (Sketch Picture1, Sketch Picture2, etc).

                 

                One solution if I rename the inserted picture, but I don't know how can I do this. Can I rename somehow the inserted picture's object?

                Ant thats it, I don't know other solution, but if somebody has any idea, please share that with me.

                 

                my code part is:

                Set swApp = Application.SldWorks

                Set Part = swApp.ActiveDoc

                .....

                Part.EditTemplate

                Set SkPicture = Part.SketchManager.InsertSketchPicture("C:\barcode.png")

                SkPicture.SetOrigin 0.0128, 0.0052

                SkPicture.SetOrigin 0.13, 0.0052

                SkPicture.SetSize 60 / 1000, 9 / 1000, True

                Part.EditSheet

                ...

                 

                thank you

                why it needs to be changed with a another new barcode?