Author Topic: Error when setting subassembly parameters C# .NET API  (Read 173 times)

0 Members and 1 Guest are viewing this topic.

jh_dempsey

  • Mosquito
  • Posts: 10
Error when setting subassembly parameters C# .NET API
« on: October 22, 2021, 05:21:52 AM »
Hi All

I am trying to programatically build some Civil 3D assemblies. My code is working, and I can build up my assemblies using existing subassemblies. I have added those assemblies into a corridor, and everything works as expected.

The next step is to be able to set some of the parameters on those subassemblies I am adding. I am using the following function to try and set some of the parameters of the subassembly once I have added it to an assembly.

Code - C#: [Select]
  1. private bool SetSubassemblyAttribute(Subassembly subassembly, string parameterName, string parameterValue)
  2.         {
  3.             // Most parameters we try to set are likely to be ones that store numbers
  4.             ParamDouble paramDouble = subassembly.ParamsDouble.Where(x => x.Key == parameterName).FirstOrDefault();
  5.             if(paramDouble != null)
  6.             {
  7.                 double parameterValueAsDouble = double.NaN;
  8.                 bool doubleParse = Double.TryParse(parameterValue, out parameterValueAsDouble);
  9.                 if(doubleParse == true)
  10.                 {              
  11.                     paramDouble.Value = parameterValueAsDouble;
  12.                     return true;
  13.                 }
  14.                 else
  15.                 {
  16.                     SimpleLog.Error("On subassembly '" + subassembly.Name + "' we could not set the subassembly parameter '" + parameterName + "' to '" + parameterValue + "' becasue the value must be a number");
  17.                     return false;
  18.                 }
  19.                
  20.             }
  21. }

However, when I step through the code when debugging, when I try and set the value using paramDouble.Value = parameterValueAsDouble; I see the message shown in the attachment
(d1sno01a.0.cs not found. You need to find d1sno01a.0.cs to view the source for the current call stack frame)

I can continue, but it screws up the subassembly object. The subassembly after this point reports that it has no points, links or shapes, which causes errors further on in my code.

If i comment out the line which calls the above function, then everything works as expected, and the subassembly reports its points/links/shapes as expected.

My initial assumption is that it would be related to not having the correct subassembly installed, but i added the subassembly to the drawing myself, and my code copies that subassembly from the drawing onto the assemblies it is creating, so I know this is not an issue with not having, or having the incorrect versions, or the subassembly DLL files.

Does anyone know why I'm getting the above error?