SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
38 stars 10 forks source link

Layout::Entity.locked= and Layout::Entity.locked? methods broken for Layout::Group Class #966

Open 3dmod opened 1 month ago

3dmod commented 1 month ago

Locked= and Locked? methods are broken for the Layout::Group Class

The following code will give the following results even though the entity is not locked when you open the file

Result

entity.locked?: false entity.locked?: true

Code

path="UPDATE TO LOCAL ENVIROMENT"
doc = Layout::Document.open(path)
ents = [
    Layout::FormattedText.new("Test1", Geom::Point2d.new(1, 1), Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT),
    Layout::FormattedText.new("Test2", Geom::Point2d.new(2, 1), Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)]
to_add = Layout::Group.new(ents)
layer = doc.layers.first
page = doc.pages.first
doc.add_entity( to_add, layer, page )
entity = 
    case
    when layer.shared?
        doc.shared_entities.to_a.last
    else
        page.nonshared_entities.to_a.last
    end
puts "entity.locked?: #{entity.locked?}"
entity.locked = true
puts "entity.locked?: #{entity.locked?}"
doc.save( path )

macOS Sonoma 14.4.1 (23E224) SketchUp Version 24.0.483

sketchup[bot] commented 1 month ago

Logged as: SKEXT-4182

ackarkka commented 1 month ago

Hello, I'm not sure I understand the issue. You are saying that initially upon creating a group that it shows that it is unlocked, then after you lock it it shows that it is locked? Is the issue that upon loading an existing file that the locked state of the group does not report correctly? Your code snippet makes a new group each time it is run so I am unsure of what you are looking for.

I also noticed this issue in your code layer = doc.pages.first should be layer = doc.layers.first.

3dmod commented 1 month ago

I want to take the following steps;

  1. create a group
  2. lock the group (Does not work)

So part one of the issue is that after I create the group and lock it does not lock.

So I set up a simplified script to troubleshoot with the following steps

  1. create a group
  2. test if group is locked. Result is correct.
  3. lock the group (Does not work)
  4. test if group is locked. Result is not correct. (Does not work)
  5. Open the saved layout file and notice that steps 3 and 4 are incorrect.

Thank you for pointing out the error in the code. It is correct in my local troubleshooting version and does not change the status of the issue.

ackarkka commented 1 month ago

I want to take the following steps;

  1. create a group
  2. lock the group (Does not work)

In my testing, step 2. is working as expected. The group is locking and subsequently reporting as locked. Unlocking and reporting the locked state afterwards also works for me locally. I am not sure why we are not seeing the same results.

3dmod commented 1 month ago

Here is a screen recording with the exact code show above not working.

I even tried using a SU made template as a possible reason without any change in outcome.

I had to downsize to 720p to make it under the 10mb GitHub file size limit.

I can email it to you if you need high resolution.

https://github.com/SketchUp/api-issue-tracker/assets/76130464/a5f42167-2fdd-4b9f-a309-042dc0d096ef

ackarkka commented 1 month ago

Thank you for the video. I was able to reproduce this through LayOut itself - Group entities are not serializing their locked status at all, and seemingly have not done so for a long time, if ever.