Author Topic: Sheet CustomProperty  (Read 3058 times)

0 Members and 1 Guest are viewing this topic.

pBe

  • Bull Frog
  • Posts: 402
Sheet CustomProperty
« on: April 11, 2019, 08:00:29 AM »
Need help with this:

Code - C#: [Select]
  1. private void TheSetSheetCustomProperty(IAcSmPersist owner, Dictionary<string, string> kval)
  2.         {
  3.             Autodesk.AutoCAD.ApplicationServices.Document activeDocument;
  4.             activeDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  5.  
  6.             // Create a reference to the Custom Property Bag
  7.             AcSmCustomPropertyBag customPropertyBag = default(AcSmCustomPropertyBag);
  8.  
  9.             if (owner.GetTypeName() == "AcSmSheet")
  10.             {
  11.                 AcSmSheet sheet = (AcSmSheet)owner;
  12.                 customPropertyBag = sheet.GetCustomPropertyBag();
  13.                 IAcSmEnumProperty enumeratorProperty;
  14.                 enumeratorProperty = customPropertyBag.GetPropertyEnumerator();
  15.  
  16.                 AcSmCustomPropertyValue customPropertyValue = null;
  17.                 enumeratorProperty.Next(out string name, out customPropertyValue);
  18.  
  19.                 while (!(customPropertyValue == null))
  20.                 {
  21.                    // if (name == propertyName)
  22.                    if  (kval.ContainsKey(name) == true)
  23.                     {
  24.                         customPropertyValue.SetValue(kval[name]); // <-- This
  25.                         customPropertyBag.SetProperty(name, customPropertyValue); // <-- and this
  26.                     }
  27.                     enumeratorProperty.Next(out name, out customPropertyValue);
  28.                 }
  29.             }
  30.         }


The IF's evaluates to TRUE but it's not setting the string value. What am I missing?

Yes, the custom property name exists on the DST file.


Jeff H

  • Needs a day job
  • Posts: 6144
Re: Sheet CustomProperty
« Reply #1 on: April 12, 2019, 05:39:59 PM »
I've use routines regularly that modify custom sheet set properties & I use the AcSmCustomPropertyValue.SetProperty() property method. I dont think Ive used the AcSmCustomPropertyBag.SetProperty(), but looks like it would be setting the property back to original value in your example.

Code - C#: [Select]
  1.                         customPropertyValue.SetValue(kval[name]); // <-- Update property
  2.                         customPropertyBag.SetProperty(name, customPropertyValue); // <--Set back to original value
  3.  

pBe

  • Bull Frog
  • Posts: 402
Re: Sheet CustomProperty
« Reply #2 on: April 15, 2019, 02:21:05 AM »
Hi Jeff,
Thank you for your reply.

I added that line thinking it would "regen" or update the value after setting the desired string. Now I commented on this line.
Code - C#: [Select]
  1. customPropertyBag.SetProperty(name, customPropertyValue)
It doesn't make a difference.

As for  AcSmCustomPropertyValue.SetProperty(). That was my first thought, but its not a valid definition for AcSmCustomPropertyValue.
Do i need to invoke a save?
Code - C#: [Select]
  1. AcSmCustomPropertyValue.Save

Is there a similar function in c# that retrieves an item from a sheet set definition much like the l method below?
Code - Auto/Visual Lisp: [Select]
  1. vla-item Sheets "The Custom Property Name"

Thank you
« Last Edit: April 15, 2019, 02:24:38 AM by pBe »

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Sheet CustomProperty
« Reply #3 on: April 15, 2019, 01:55:20 PM »
I will double check but from I remember you call save on the database.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Sheet CustomProperty
« Reply #4 on: April 15, 2019, 05:27:06 PM »
Also I wrote a little library that helps grabbing the sheets, etc.... where you dont have do the old style of using enumerators and just grab them in a for each loop from the sheet, will dig it out this week.


pBe

  • Bull Frog
  • Posts: 402
Re: Sheet CustomProperty
« Reply #5 on: April 22, 2019, 12:51:04 PM »
Thank you for your help Jeff.

I found out what's wrong. I had this line at the bottom of the code.
Code - C#: [Select]
  1. SyncProperties(sheetSetDatabase)
Passing the values from the Custom property down the subset line. I picked it up from AU09_Presentation_CP318-4

My bad.

A different item.
I use this to open a sheet set file
Code - C#: [Select]
  1. doc.SendStringToExecute("._-opensheetset " + yourSheetSetFilePath + "\n", false, false, true);
Question now is. How do close an opened sheet set fiel from the Sheetset Manager?


Jeff H

  • Needs a day job
  • Posts: 6144
Re: Sheet CustomProperty
« Reply #6 on: April 23, 2019, 02:26:35 PM »
I'm sure you can, but I never done that. I typically require just one sheetset to be open in the sheetsetmanager before the code executes.