Author Topic: Getring custom "Name" of a AcSmCustomPropertyValue  (Read 1604 times)

0 Members and 1 Guest are viewing this topic.

pBe

  • Bull Frog
  • Posts: 402
Getring custom "Name" of a AcSmCustomPropertyValue
« on: September 20, 2016, 04:23:36 AM »
I have this code that writes the Custom Property Value of the entire sheet set. What i'm trying to achieve is not just retrieve all custom values BUT it should meet a certain condition. That's where the custom name comes into play,

The names of the custom properties are:

"Property 1"
"Property 2"
"Property 3"

So, only if the "name" is any of the above, then give me the value. Having a hard time figuring out where Sheet set database keeps this value, and on top of that , i also need to know the file sheet name where those property values belongs to,

Ground Floor.
Property 1 =  15A
Property 2 =  892
Property 3 =  Room 1

Here's the code
Code - C#: [Select]
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Collections.Generic;
  4. using System.Windows.Documents;
  5.  
  6. using Autodesk.AutoCAD.Windows;
  7. using Autodesk.AutoCAD.Runtime;
  8. using Autodesk.AutoCAD.ApplicationServices;
  9. using Autodesk.AutoCAD.DatabaseServices;
  10. using Autodesk.AutoCAD.Geometry;
  11. using Autodesk.AutoCAD.EditorInput;
  12.  
  13. using ACSMCOMPONENTS20Lib;
  14.  
  15. // This line is not mandatory, but improves loading performances
  16. [assembly: CommandClass(typeof(CLL_Drawing_list.MyCommands))]
  17.  
  18.  
  19. namespace CLL_Drawing_list
  20. {
  21.  
  22.     public class MyCommands
  23.     {
  24.         // Counts up the sheets for all the open sheet sets
  25.         [CommandMethod("SetSheetPropNames")]
  26.         public void SetSheetCount()
  27.         {
  28.             Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  29.             Document dwg = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
  30.             Editor ed = dwg.Editor;
  31.  
  32.  
  33.             PromptStringOptions ssFile = new PromptStringOptions("\nEnter Sheet Set Name: ");
  34.             ssFile.AllowSpaces = true;
  35.             PromptResult ssFileRes = acDoc.Editor.GetString(ssFile);
  36.  
  37.             string ssFilePath = (ssFileRes.StringResult);
  38.  
  39.             AcSmSheetSetMgr sheetSetManager = new AcSmSheetSetMgr();
  40.             IAcSmDatabase db = sheetSetManager.OpenDatabase(ssFilePath , false);
  41.             IAcSmSheetSet ss = db.GetSheetSet();
  42.  
  43.             int nSheetCount = 0;
  44.            
  45.             //// Get a reference to the Sheet Set Manager object
  46.             //IAcSmSheetSetMgr sheetSetManager = new AcSmSheetSetMgr();
  47.  
  48.             // Get the loaded databases
  49.             IAcSmEnumDatabase enumDatabase = sheetSetManager.GetDatabaseEnumerator();
  50.  
  51.             // Get the first open database
  52.             IAcSmPersist item = enumDatabase.Next();
  53.  
  54.             AcSmDatabase sheetSetDatabase = default(AcSmDatabase);
  55.  
  56.             while ((item != null))
  57.             {
  58.                 sheetSetDatabase = (AcSmDatabase)item;
  59.  
  60.  
  61.                 // Attempt to lock the database
  62.                 if (LockDatabase(ref sheetSetDatabase, true) == true)
  63.                 {
  64.                     // Get the enumerator for the objects in the sheet set
  65.                     IAcSmEnumPersist enumerator = sheetSetDatabase.GetEnumerator();
  66.                     IAcSmPersist itemSheetSet = enumerator.Next();
  67.  
  68.                     // Step through the objects in the sheet set
  69.                     while ((itemSheetSet != null))
  70.                     {
  71.                         // Increment the counter of the object is a sheet
  72.                         if (itemSheetSet.GetTypeName() == "AcSmCustomPropertyValue")
  73.                         {
  74.                             nSheetCount = nSheetCount + 1;
  75.                             ed.WriteMessage("\nNumber of Custom Property so far.." + nSheetCount.ToString());
  76.  
  77.  
  78.                             AcSmCustomPropertyValue pv = (AcSmCustomPropertyValue)itemSheetSet;
  79.                            
  80.                             try
  81.                             {
  82.                                 string sValue = pv.GetValue().ToString();
  83.                                 ed.WriteMessage("\nThis item is......" + pv.GetValue().ToString());
  84.                              
  85.                             }
  86.                             catch { }
  87.  
  88.                         }
  89.                         {
  90.                             itemSheetSet = enumerator.Next();
  91.  
  92.                         }
  93.                     }
  94.  
  95.  
  96.                     // Create a sheet set property
  97.                     // SetCustomProperty(sheetSetDatabase.GetSheetSet(), "Total Sheets", nSheetCount.ToString(), PropertyFlags.CUSTOM_SHEETSET_PROP);
  98.  
  99.                     // Unlock the database
  100.                     LockDatabase(ref sheetSetDatabase, false);
  101.  
  102.  
  103.                     // Clear and check for the next open sheet set
  104.                     nSheetCount = 0;
  105.                 }
  106.                 else
  107.                 {
  108.                     MessageBox.Show("Unable to access " + sheetSetDatabase.GetSheetSet().GetName());
  109.                 }
  110.  
  111.                 item = enumDatabase.Next();
  112.             }
  113.         }
  114.  
  115.         // Used to lock/unlock a sheet set database
  116.         private bool LockDatabase(ref AcSmDatabase database, bool lockFlag)
  117.         {
  118.             bool dbLock = false;
  119.             // If lockFalg equals True then attempt to lock the database, otherwise
  120.             // attempt to unlock it.
  121.             if (lockFlag == true & database.GetLockStatus() == AcSmLockStatus.AcSmLockStatus_UnLocked)
  122.             {
  123.                 database.LockDb(database);
  124.                 dbLock = true;
  125.             }
  126.             else if (lockFlag == false && database.GetLockStatus() == AcSmLockStatus.AcSmLockStatus_Locked_Local)
  127.             {
  128.                 database.UnlockDb(database, true);
  129.                 dbLock = true;
  130.             }
  131.             else
  132.             {
  133.                 dbLock = false;
  134.             }
  135.  
  136.             return dbLock;
  137.         }
  138.     }
  139.  
  140. }
  141. [code][/font]
  142.  
  143. [font=verdana]Any help would be appreciated [/font]
  144.  
  145. [font=verdana]Thank you[/font]
  146.  
« Last Edit: September 20, 2016, 01:00:20 PM by pBe »

pBe

  • Bull Frog
  • Posts: 402
Re: Getring custom "Name" of a AcSmCustomPropertyValue
« Reply #1 on: September 20, 2016, 09:36:15 AM »
Now i was able to retrieve Names and Values BUT only on the first level using this code

Code - C#: [Select]
  1.  
  2. Abandoned....
  3.  
  4.  


Cant seem to get pass the first level
Thoughts anyone?


EDIT:
Now able to get the sheet name.....
Got the "Property Name" as well .. almost there...
Got it.
« Last Edit: September 21, 2016, 11:10:10 AM by pBe »