7 Replies Latest reply on Feb 16, 2015 12:10 AM by Stamm

    Path strokeWeight is '1' when it is not set?

    Stamm Level 1

      Screen Shot 2015-02-12 at 17.20.20.png

       

      Hey guys,

       

      on the picture you can see the selected path, an alert with the code "alert(app.selection[0].strokeWeight)" and all relevant information. Why is it saying "1" when stroke is not set?

      On every other element it is showing "0" when no stroke is set. So A: is there a workaround this? and B: why does this happen?

       

      Thanks in advance!

        • 1. Re: Path strokeWeight is '1' when it is not set?
          Laubender Adobe Community Professional & MVP

          @Stamm – this polygon is copied from Adobe Illustrator to InDesign.

           

          The recipe of getting this is:

           

          1. Draw a shape in Illustrator CC-2014.1.1 v18.1.1

          2. Fill the shape

          3. Set the color of the stroke to "None"

          4. Copy

          5. Paste to InDesign

           

          SelectedPolygonPastedFromIllustrator.png

           

          This will even happen, if you do actively set the stroke weight in Illustrator to zero!

          Here an example with an "undefined" stroke weight. Fill color "None" in Illustrator. But even if you set it explicitly to zero, you will get what the alert says.

           

          PolygonInIllustrator.png

           

          So why the different results?


          I see a difference, if one would:


          1. Set the fill color in Illustrator

          2. Set the stroke color in Illustrator

          3. Copy

          4. Paste to InDesign

          5. Set the stroke weight to zero

           

           

          Uwe

          • 2. Re: Path strokeWeight is '1' when it is not set?
            Laubender Adobe Community Professional & MVP

            Now, I think, we know the "how".

            Let's go on with the "why"…

             

            I can only speculate here.


            Could be that is has to do with the fact, that you cannot copy/paste a path from Illustrator to InDesign where no stroke weight and no fill color is applied to the object. Why that is, why that restriction, I will never understand. Even if you will group an "empty" path to a filled path in Illustrator and copy/paste that group to InDesign, only the filled path will be placed on the spread in InDesign. ?? !! ?? Isn't that a bit insane?

             

            Maybe, that every "pastable" path object you paste to InDesign from Illustrator has to have a stroke weight?
            And if no stroke weight is defined in Illustrator, you'll get the "standard" or "default" 1 point?

            Could well be.

             

            Then "what" can we do about it in InDesign?

            We can detect those path objects by simply looking at two properties and their values:

             

            strokeWeight && fillColor.name

             

            if(myObject.strokeWeight > 0 && myObject.fillColor.name === "None"){ /*Pasted from outside. Maybe Illustrator*/ }
            

             

            What you now want to do with it is up to you.

             

            Note: The visible bounds and the geometric bounds of a simple pasted object from Illustrator are the same.

            Even when the stroke weight is 1 point. And that's ok. You set "None", visibly you get "None".

             

            Why now the UI is "thinking" that the stroke weight is zero, is a different thing…

             

            Uwe

            • 3. Re: Path strokeWeight is '1' when it is not set?
              Laubender Adobe Community Professional & MVP

              And the whole case reminds me on new means since InDesign CC 2014.2 is out, to transfer objects from Illustrator to InDesign:
              CC Library assets


              If you store a path object in Illustrator to a CC Library and place that in InDesign, the stroke weight will be set to zero, if no stroke is applied in Illustrator.

              You can also transfer empty paths this way…

               

              Currently I cannot tell, if the usage of CC Libraries is scriptable by any means.
              There is no new object like a "CCLibrary Object" in InDesign's "Application Object".

              Only the normal "Library Object" with all its properties and methods to place assets on the spread.

               

              Uwe

              • 4. Re: Path strokeWeight is '1' when it is not set?
                Stamm Level 1

                Hey Uwe,

                 

                thanks for the response. I just realised something. If it is really that easy, it would be awesome. Can't I just use:

                 

                if(app.selection[0].strokeColor.hasOwnProperty('colorValue') || app.selection[0].strokeColor instanceof Gradient)

                    alert('yup');

                 

                When I tested this, it worked every time.

                 

                The problem with your solution is, that the code I'm working on should be working for pretty much every case. And it would be too much effort if my coworkers would need to implement every single path as .ai.

                • 5. Re: Path strokeWeight is '1' when it is not set?
                  Laubender Adobe Community Professional & MVP

                  @Stamm – In my answer #2 I made a sorry mistake.

                  The if-statement should read like that:

                   

                  if(myObject.strokeWeight > 0 && myObject.strokeColor.name === "None"){ /*Pasted from outside. Maybe Illustrator*/ }
                  
                  

                   

                  I hope, you realised that…

                  In fact I tested exactly with the above line of code.

                   

                  Now on to your if-statement.
                  Why instanceof Gradient ??

                   

                  What should your if-statement catch?
                  The good ones? Those with strokeWeight value 0 ?

                  The bad ones? Those with strokeWeight value 1 and strokeColor value "None" ?

                   

                  Does ist make a difference for the user?
                  I'm not sure what you are trying to accomplish with the found polygons.

                  The "normal"kind or the other, the "odd" kind…

                   

                  Uwe

                   

                  //Minor edits

                  • 6. Re: Path strokeWeight is '1' when it is not set?
                    Laubender Adobe Community Professional & MVP

                    @Stamm – quite another thing related:

                     

                    To transfer paths from Illustrator to InDesign is now possible with CC Libraries.
                    Add a path to a CC Library in Illustrator 2014.

                    Switch to InDesign CC 2014.2.

                    Drag that path out to an InDesign page.

                     

                    No problems anymore with the invisible 1pt stroke weights.

                     

                    Also and important:
                    You can also do this with empty paths objects from Illustrator.

                     

                    Copy/paste of empty paths from Illustrator to InDesign is not possible.

                    Even if they are part of a group with other paths with a fill color or a stroke color.

                    If you copy/paste a group of Illustrator paths to InDesign only the ones with a fill color or a stroke color will survive.

                    And there is no error message in this case.

                     

                    Uwe

                    • 7. Re: Path strokeWeight is '1' when it is not set?
                      Stamm Level 1

                      For the explanation: When a path has strokeColor "none" the hasOwnProperty and the instanceof gradient will both return false. And a path always has stroke "none" when the strokeWeight is set to 0. So instead of testing for strokeWeight, I figured we could just test for strokeColor, and if this is true, we can then surely test the strokeWeight. Isn't it working like that?