Exemplo n.º 1
0
        private bool SetHandle(IXAssembly assm, HandleType_e handleType)
        {
            var assmDir = Path.GetDirectoryName(assm.Path);

            var handleFileName = "";

            switch (handleType)
            {
            case HandleType_e.C:
                handleFileName = "Handle-C.SLDPRT";
                break;

            case HandleType_e.D:
                handleFileName = "Handle-D.SLDPRT";
                break;

            case HandleType_e.W:
                handleFileName = "Handle-W.SLDPRT";
                break;

            default:
                throw new NotSupportedException("Handle type is not supported");
            }

            var handleFilePath = Path.Combine(assmDir, handleFileName);

            var handleComps = assm.Configurations.Active.Components.Where(
                c => c.Name.StartsWith("Handle-", StringComparison.CurrentCultureIgnoreCase) &&
                !string.Equals(c.Path, handleFilePath, StringComparison.CurrentCultureIgnoreCase)).ToArray();

            if (handleComps.Any())
            {
                assm.Selections.AddRange(handleComps);

                if (!((ISwAssembly)assm).Assembly.ReplaceComponents2(handleFilePath,
                                                                     "Default", true, (int)swReplaceComponentsConfiguration_e.swReplaceComponentsConfiguration_MatchName, true))
                {
                    throw new Exception("Failed to replace handle");
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public void Configure(IXAssembly assm, double width, double height, double depth, int drawersCount, double drawerWidth, HandleType_e handleType)
        {
            var hasChanges = SetParameters(assm, width, height, depth, drawersCount, drawerWidth);

            hasChanges |= SetHandle(assm, handleType);

            if (hasChanges)
            {
                assm.Rebuild();
            }
        }