xBimTeam / XbimGeometry

XbimGeometry contains the CLR interop libraries and the c++ engine used to compute the 3D geometry of models.
https://xbimteam.github.io/
Other
260 stars 132 forks source link

Too many parameters for constructor of type 'IfcCartesianPointList3D' #291

Closed stenfalp closed 4 years ago

stenfalp commented 4 years ago

Cannot create a valid IfcCartesianPointList3D

Assemblies and versions affected:

Xbim.Ifc4.5.1.297

Steps (or code) to reproduce the issue:

IfcCartesianPointList3D pointList = model.Instances.New<IfcCartesianPointList3D>();
pointList.CoordList.GetAt(0).AddRange(new IfcLengthMeasure[] { 0, 0, 0 });
pointList.CoordList.GetAt(1).AddRange(new IfcLengthMeasure[] { 0, 0, 1 });

Expected behavior:

80=IFCCARTESIANPOINTLIST3D(((0.,0.,0.),(0.,0.,1.)));

Actual behavior or exception details:

80=IFCCARTESIANPOINTLIST3D(((0.,0.,0.),(0.,0.,1.)),$);

Additional Details

Checked with ifcCheckingTool Version 2.0 (Build 80) - 23. September 2019

martin1cerny commented 4 years ago

Can you try with the latest packages? It is most likely misalignment between versions of packages you use. Try to remove all references to xbim and only reference XbimEssentials package.

stenfalp commented 4 years ago

It seems all uptodate for me. Here is an excerpt of my project file:

<ItemGroup>
    <Reference Include="Esent.Interop, Version=1.9.4.1, Culture=neutral, processorArchitecture=MSIL">
      <HintPath>packages\ManagedEsent.2.0.0\lib\netstandard2.0\Esent.Interop.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>packages\Microsoft.Bcl.AsyncInterfaces.1.1.1\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Extensions.Configuration, Version=3.1.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
      <HintPath>packages\Microsoft.Extensions.Configuration.3.1.8\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Extensions.Configuration.Abstractions, Version=3.1.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
      <HintPath>packages\Microsoft.Extensions.Configuration.Abstractions.3.1.8\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Extensions.Configuration.Binder, Version=3.1.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
      <HintPath>packages\Microsoft.Extensions.Configuration.Binder.3.1.8\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Extensions.DependencyInjection, Version=3.1.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
      <HintPath>packages\Microsoft.Extensions.DependencyInjection.3.1.8\lib\net461\Microsoft.Extensions.DependencyInjection.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=3.1.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
      <HintPath>packages\Microsoft.Extensions.DependencyInjection.Abstractions.3.1.8\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Extensions.Logging, Version=3.1.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
      <HintPath>packages\Microsoft.Extensions.Logging.3.1.8\lib\netstandard2.0\Microsoft.Extensions.Logging.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=3.1.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
      <HintPath>packages\Microsoft.Extensions.Logging.Abstractions.3.1.8\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Extensions.Options, Version=3.1.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
      <HintPath>packages\Microsoft.Extensions.Options.3.1.8\lib\netstandard2.0\Microsoft.Extensions.Options.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Extensions.Primitives, Version=3.1.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
      <HintPath>packages\Microsoft.Extensions.Primitives.3.1.8\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
    </Reference>
    <Reference Include="System.ComponentModel.Annotations, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>packages\System.ComponentModel.Annotations.4.7.0\lib\net461\System.ComponentModel.Annotations.dll</HintPath>
    </Reference>
    <Reference Include="System.ComponentModel.DataAnnotations" />
    <Reference Include="System.Configuration" />
    <Reference Include="System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>packages\System.Configuration.ConfigurationManager.4.7.0\lib\net461\System.Configuration.ConfigurationManager.dll</HintPath>
    </Reference>
    <Reference Include="System.Core" />
    <Reference Include="System.Data.OracleClient" />
    <Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
    </Reference>
    <Reference Include="System.Net" />
    <Reference Include="System.Numerics" />
    <Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
    </Reference>
    <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
    </Reference>
    <Reference Include="System.Security" />
    <Reference Include="System.Security.AccessControl, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll</HintPath>
    </Reference>
    <Reference Include="System.Security.Permissions, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>packages\System.Security.Permissions.4.7.0\lib\net461\System.Security.Permissions.dll</HintPath>
    </Reference>
    <Reference Include="System.Security.Principal.Windows, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll</HintPath>
    </Reference>
    <Reference Include="System.ServiceProcess" />
    <Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
    </Reference>
    <Reference Include="System.Transactions" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Deployment" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml" />
    <Reference Include="WindowsBase" />
    <Reference Include="Xbim.Common, Version=5.1.0.0, Culture=neutral, PublicKeyToken=11e3655e576ec5a9, processorArchitecture=MSIL">
      <HintPath>packages\Xbim.Common.5.1.297\lib\net47\Xbim.Common.dll</HintPath>
    </Reference>
    <Reference Include="Xbim.Ifc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=11e3655e576ec5a9, processorArchitecture=MSIL">
      <HintPath>packages\Xbim.Ifc.5.1.297\lib\net47\Xbim.Ifc.dll</HintPath>
    </Reference>
    <Reference Include="Xbim.Ifc2x3, Version=5.1.0.0, Culture=neutral, PublicKeyToken=11e3655e576ec5a9, processorArchitecture=MSIL">
      <HintPath>packages\Xbim.Ifc2x3.5.1.297\lib\net47\Xbim.Ifc2x3.dll</HintPath>
    </Reference>
    <Reference Include="Xbim.Ifc4, Version=5.1.0.0, Culture=neutral, PublicKeyToken=11e3655e576ec5a9, processorArchitecture=MSIL">
      <HintPath>packages\Xbim.Ifc4.5.1.297\lib\net47\Xbim.Ifc4.dll</HintPath>
    </Reference>
    <Reference Include="Xbim.IO.Esent, Version=5.1.0.0, Culture=neutral, PublicKeyToken=11e3655e576ec5a9, processorArchitecture=MSIL">
      <HintPath>packages\Xbim.IO.Esent.5.1.297\lib\net47\Xbim.IO.Esent.dll</HintPath>
    </Reference>
    <Reference Include="Xbim.IO.MemoryModel, Version=5.1.0.0, Culture=neutral, PublicKeyToken=11e3655e576ec5a9, processorArchitecture=MSIL">
      <HintPath>packages\Xbim.IO.MemoryModel.5.1.297\lib\net47\Xbim.IO.MemoryModel.dll</HintPath>
    </Reference>
    <Reference Include="Xbim.Tessellator, Version=5.1.0.0, Culture=neutral, PublicKeyToken=11e3655e576ec5a9, processorArchitecture=MSIL">
      <HintPath>packages\Xbim.Tessellator.5.1.297\lib\net47\Xbim.Tessellator.dll</HintPath>
    </Reference>
  </ItemGroup>
martin1cerny commented 4 years ago

I'm sorry, I misread the package version in the original message.

However, I just tried and everything works for me:

using Xbim.Common.Step21;
using Xbim.Ifc;
using Xbim.Ifc4.GeometricModelResource;
using Xbim.Ifc4.MeasureResource;
using Xbim.IO;

namespace BasicExamples
{
    public class NestedCartesianPointListExample
    {
        public static void Run()
        {
            using (var model = IfcStore.Create(XbimSchemaVersion.Ifc4, XbimStoreType.InMemoryModel))
            {
                using (var txn = model.BeginTransaction())
                {
                    var pointList = model.Instances.New<IfcCartesianPointList3D>(cpl =>
                    {
                        cpl.CoordList.GetAt(0).AddRange(new IfcLengthMeasure[] { 122.544, 445.151, 13.673 });
                        cpl.CoordList.GetAt(1).AddRange(new IfcLengthMeasure[] { 137.671, 442.768, 13.7401 });
                        cpl.CoordList.GetAt(2).AddRange(new IfcLengthMeasure[] { 142.393, 462.543, 11.4145 });
                    });
                    txn.Commit();
                }
                model.SaveAs("IfcCartesianPointList3D.ifc");
            }
        }
    }
}

This produces this file as expected:

ISO-10303-21;
HEADER;
FILE_DESCRIPTION ((''), '2;1');
FILE_NAME ('', '2020-10-09T13:46:32', (''), (''), 'Processor version 5.1.0.0', 'Xbim.IO.MemoryModel', '');
FILE_SCHEMA (('IFC4'));
ENDSEC;
DATA;
#1=IFCCARTESIANPOINTLIST3D(((122.544,445.151,13.673),(137.671,442.768,13.7401),(142.393,462.543,11.4145)),$);
ENDSEC;
END-ISO-10303-21;
stenfalp commented 4 years ago

Sorry, but the problem is still there: the characters ,$ should not be present.

martin1cerny commented 4 years ago

This is a TagList from IFC4x1. This is a valid extension according to ISO. Extra parameters can be added to the end of the object.

stenfalp commented 4 years ago

OK, sorry.

stenfalp commented 4 years ago

In addition to KIT's IFCCheckingTool also Revit 2021 complaints for the same problem: Recoverable Error: Wrong number of attributes; expected: 1 found: 2 on line 384.

Please note that I am exporting in IFC4, not IFC4.1 (XbimSchemaVersion.Ifc4).

martin1cerny commented 4 years ago

This is a backwards compatibility feature of STEP21 format and these tools should not crash. But I know there is usually little you can do about 3rd party SW. You can relatively easily use your own custom writer with a workaround:

using System.IO;
using Xbim.Common;
using Xbim.Common.Metadata;
using Xbim.Ifc4.GeometricModelResource;
using Xbim.IO.Step21;

namespace BasicExamples
{
    internal class CustomStep21Writer
    {
        public static void Save(TextWriter writer, IModel model)
        {
            Part21Writer.WriteHeader(model.Header, writer, "IFC4");
            var metadata = model.Metadata;
            foreach (var instance in model.Instances)
                WriteEntity(instance, writer, metadata);
            Part21Writer.WriteFooter(writer);
        }

        private static void WriteEntity(IPersistEntity entity, TextWriter output, ExpressMetaData metadata)
        {
            var expressType = metadata.ExpressType(entity);
            output.Write("#{0}={1}(", entity.EntityLabel, expressType.ExpressNameUpper);

            var first = true;

            foreach (var ifcProperty in expressType.Properties.Values)
            //only write out persistent attributes, ignore inverses
            {
                if (ifcProperty.EntityAttribute.State == EntityAttributeState.DerivedOverride)
                {
                    if (!first)
                        output.Write(',');
                    output.Write('*');
                    first = false;
                }
                else
                {
                    // workaround for IfcCartesianPointList3D from IFC4x1
                    if (entity is IfcCartesianPointList3D && ifcProperty.Name == "TagList")
                        continue;

                    var propType = ifcProperty.PropertyInfo.PropertyType;
                    var propVal = ifcProperty.PropertyInfo.GetValue(entity, null);
                    if (!first)
                        output.Write(',');
                    Part21Writer.WriteProperty(propType, propVal, output, null, metadata);
                    first = false;
                }
            }
            output.Write(");");
        }
    }
}
stenfalp commented 4 years ago

Good to know. Thank you very much Martin.