cart: empty [ Login ]

Evaluate dynamic visibility parameter

1 
Aluro
1/10/2024 3:26 PM
Hi, After getting the visibility parameter from the dynamic block, how do then evaluate it for a given insert of that block?
C# Code:
var opvBlockInsertA = opvBlockInserts.ElementAtOrDefault(0); var opvBlockInsertB = opvBlockInserts.ElementAtOrDefault(1); var opvBlock = dwg.Blocks["9999.0110.016902-00"]; DxfDictionary extensionDictionary = opvBlock.ExtensionDictionary; DxfEvalGraph graph = (DxfEvalGraph)extensionDictionary.GetValueByName("ACAD_ENHANCEDBLOCK"); var visParam = graph.Nodes.FirstOrDefault(i => i.Expression is DxfBlockVisibilityParameter par && par.LabelText.Equals("Stopper", StringComparison.OrdinalIgnoreCase))?.Expression as DxfBlockVisibilityParameter; // TODO: get the visibility state that is active for a given insert // var visStateA = visParam?.GetStateForInsert(opvBlockInsertA); // var visStateB = visParam?.GetStateForInsert(opvBlockInsertB);
Wout
1/16/2024 12:33 PM
Hi, I have no idea! Could you attach a DXF/DWG file for me to look at (if possible just stripped down to the relevant parts)? And also add a small program that pin points the objects of interest would be useful. - Wout
Aluro
1/19/2024 2:39 PM
Attached are some example files. In the DWG I've added a single dynamic block with a visibility parameter called 'mood' which has 2 states 'happy' and 'sad'. I've also added 2 inserts of the dynamic block each set to a different state.
Wout
1/23/2024 1:48 PM
Hi, I've investigated it and come up with a preliminary implementation and may not work in all scenarios. There is no public documentation for any of this so it takes some reverse engineering figuring out what goes where. Could you please order a support ticket here for the support?
C# Code:
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using WW.Cad.IO; using WW.Cad.Model; using WW.Cad.Model.Entities; using WW.Cad.Model.Objects; using WW.Cad.Model.Objects.DynamicBlock; using WW.Cad.Model.Tables; namespace ConsoleApplication { public static class CustomerProblem { public static void CustomerMain(string[] args) { Test(args); } static void Test(string[] args) { GetMoodVisibilityStates(@"C:\support\aluro\1\dynamic_visibility.dwg"); } private static void GetMoodVisibilityStates(string path) { var dwg = DwgReader.Read(path); foreach (var entity in dwg.Entities) { var emoticonInsert = entity as DxfInsert; if (emoticonInsert != null) { var mood = getVisibilityState(dwg, emoticonInsert, "Mood"); Debug.WriteLine($"Emoticon is '{mood}'"); } } } static string getVisibilityState(DxfModel model, DxfInsert insertOfDynamicBlock, string parameterName) { string state = string.Empty; DxfAppId appId; if (model.AppIds.TryGetValue("AcDbBlockRepBTag", out appId)) { DxfBlock dynamicBlock = (DxfBlock)insertOfDynamicBlock.Block.ExtendedDataCollection[appId].Values[1].ValueObject; var enhancedDict = (DxfEvalGraph)dynamicBlock.ExtensionDictionary.GetValueByName("ACAD_ENHANCEDBLOCK"); var parameter = (DxfBlockVisibilityParameter)enhancedDict.Nodes.FirstOrDefault( i => i.Expression is DxfBlockVisibilityParameter par && par.LabelText.Equals(parameterName, StringComparison.OrdinalIgnoreCase) ).Expression; // TODO, get actual state: var state = parameter.GetVisibilityState(insertOfDynamicBlock); var visibilityState = parameter.VisibilityStates.First(); state = GetParameterValue(insertOfDynamicBlock, parameter); } return state; } // Get the parameter value from the insert. private static string GetParameterValue(DxfInsert insert, DxfBlockParameter parameter) { string state = string.Empty; var blockRepresentation = insert.ExtensionDictionary.GetValueByName("AcDbBlockRepresentation") as DxfDictionary; if (blockRepresentation != null) { var dataCache = blockRepresentation.GetValueByName("AppDataCache") as DxfDictionary; if (dataCache != null) { var enhancedBlockData = dataCache.GetValueByName("ACAD_ENHANCEDBLOCKDATA") as DxfDictionary; if (enhancedBlockData != null) { // These are numbered entries "1", etc, might refer to node Id. var xrecord = enhancedBlockData.GetValueByName(parameter.NodeId.Id.ToString()) as DxfXRecord; if (xrecord != null) { // Unsure about all the xrecord value meanings, but the values[5] seems to contain the parameter value for the insert. state = xrecord.Values[5].Value.ToString(); } } } } return state; } } }
- Wout
Aluro
1/24/2024 7:10 AM
Hi Wout, thanks for the investigation. We'll continue our discussion by mail.
1