2017년 3월 27일 월요일

[Civil3D API] How to make autoloading install file for .NET assembly.

There are some way to make a autoloading install for .NET assembly.
1. The way to use .lsp file at startup.
2. The way to use PackageContents.xml at startup.

Now I will explain about second way.
Second way is most new way and recommanded way.

First, PackageContents.xml file has to be in ***.bundle directory in the %appdata%Autodesk/ApplicationPlugins.

And Other needed files like .dll or .png are in the ***.bundle directory or sub directory of one.

Most important things are  directory name and contents of PackageContents.xml.
Directory name has to include .bundle at the last.
packageContents.xml file has to include information about command what you need.
Last, if you want to make ribbon at loading assembly(.dll), you have to observe the following rule.
Rule.
  - You have to call a function to make ribbon at startup when SystemVariableChanged event is happened. And you have to delete that event handler method.
  - Reference following codes.
  public class InitializeKoreaModule : IExtensionApplication
    {
        public void Initialize()
        {
            Autodesk.AutoCAD.ApplicationServices.Application.SystemVariableChanged += Application_SystemVariableChanged;
        }

        void Application_SystemVariableChanged(object sender, Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs e)
        {
            if (Autodesk.Windows.ComponentManager.Ribbon != null)
            {
                //ok, create Ribbon
                LoadRibbon();
                //and remove the event handler
                Autodesk.AutoCAD.ApplicationServices.Application.SystemVariableChanged -= Application_SystemVariableChanged;
            }
        }

        public void Terminate()
        {

        }

        public void LoadRibbon()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;

            RibbonTab rbTabKorea = CreateRibbon("Korea");
            if (rbTabKorea == null)
            {
                return;
            }

            RibbonPanelSource rbPanelSuperelevation = CreateButtonPannel("Superelevation", rbTabKorea);
            if (rbPanelSuperelevation != null)
            {
                rbPanelSuperelevation.Items.Add(CreateButton("Superelevation\nPlanar Figure", "SPF", "HangilIT.C3DCountryKit.Resources.product-icon.png"));
//                rbPanelSuperelevation.Items.Add(new RibbonRowBreak());
            }

            RibbonPanelSource rbPanelEarthWork = CreateButtonPannel("Earth Work Carried Quantities", rbTabKorea);
            if (rbPanelEarthWork != null)
            {
                rbPanelEarthWork.Items.Add(CreateButton("Earth Work\nCalculation", "ECC", "HangilIT.C3DCountryKit.Resources.product-icon.png"));
                rbPanelEarthWork.Items.Add(CreateButton("Mass Curve", "MC", "HangilIT.C3DCountryKit.Resources.product-icon.png"));
                rbPanelEarthWork.Items.Add(CreateButton("Mass Haul", "MH", "HangilIT.C3DCountryKit.Resources.product-icon.png"));
            }
        }

        private RibbonTab CreateRibbon(string str)
        {
            // 리본 컨트롤 생성
            RibbonControl rc = ComponentManager.Ribbon;

            // 리본 탭 검색
            RibbonTab rt = rc.FindTab(str);
            if (rt == null)
            {
                // 리본 탭 생성
                rt = new RibbonTab();
                // 리본탭 정보
                rt.Title = str;
                rt.Id = str;
                // 리본 컨트롤에 리본탭 추가
                rc.Tabs.Add(rt);
            }
            
            // 리본탭 활성화
            rt.IsActive = true;

            return rt;
        }

        private RibbonPanelSource CreateButtonPannel(string str, RibbonTab rtab)
        {
            // 리본 패널 소스 생성
            RibbonPanelSource bp = new RibbonPanelSource();
            // 리본 패널 소스 정보
            bp.Title = str;
            // 리본 패널 생성
            RibbonPanel rp = new RibbonPanel();
            // 리본 패널에 리본 패널 소스 추가
            rp.Source = bp;
            // 리본 탭에 리본 패널 추가
            rtab.Panels.Add(rp);

            return bp;
        }

        private RibbonButton CreateButton(string str, string CommandParameter, string pngFile)
        {
            // 리본 버튼 생성
            RibbonButton button = new RibbonButton();
            // 리본 버튼 정보
            button.Text = str;
            button.Id = str;
            button.CommandParameter = CommandParameter; // name of the command
            button.ShowImage = true;
            button.ShowText = true;
            button.Size = RibbonItemSize.Large;
            button.Orientation = Orientation.Vertical;
            button.LargeImage = UtilityEtc.LoadImage(pngFile);
            // to add command to the button write the line below
            button.CommandHandler = new AdskCommandHandler();

            return button;
        }
    }


Detail information about PackageContents.xml file is in following link.
http://adndevblog.typepad.com/autocad/2013/01/autodesk-autoloader-white-paper.html


댓글 없음:

댓글 쓰기