本帖最后由 NetBee 于 2012-5-2 21:38 编辑
貌似.net才行呀。
- 1- Using VS2005 for AutoCAD 2009:
-
- -- In stdafx.h add this lines:
- #using <mscorlib.dll>
- #using <System.dll>
- #using <acdbmgd.dll>
- #using <acmgd.dll>
- #using <AcRibbon.dll>
- #using <AdWindows.dll>
- #using <PresentationCore.dll>
- #using <PresentationFramework.dll>
- #using <WindowsBase.dll>
-
- --- MyRibbonTabProxy.h
- #pragma once
- #include "StdAfx.h"
- using namespace System;
- using namespace Autodesk::Windows;
- using namespace Autodesk::AutoCAD::Ribbon;
- void MakeIt(void);
- public __gc class MyRibbonTabProxy
- {
- private:
- RibbonTab* m_RibTab;
- public:
- MyRibbonTabProxy(String* title, String* id );
- protected:
- void OnButtonClick(Object* sender, Windows::RoutedEventArgs * ea);
- };
-
- --- MyRibbonTabProxy.cpp
- #include "StdAfx.h"
- #include "MyRibbonTabProxy.h"
-
- void MakeIt()
- {
- MyRibbonTabProxy* rb = new MyRibbonTabProxy( S"CadOfiTec", S"CadOfiTecTab" );
- }
- MyRibbonTabProxy::MyRibbonTabProxy(String* title, String* id )
- {
- RibbonControl* ribCtrl = Autodesk::AutoCAD::Ribbon::RibbonServices::RibbonPaletteSet->RibbonControl;
- if( ribCtrl == NULL )
- return;
-
- m_RibTab = ribCtrl->FindTab( id );
- if( m_RibTab != NULL )
- return;
- m_RibTab = new RibbonTab();
- m_RibTab->Title = title;
- m_RibTab->Id = id;
- ribCtrl->Tabs->Add( m_RibTab );
- m_RibTab->IsActive = true;
- // Create the panel source
- RibbonPanelSource* ribSourcePanel = new RibbonPanelSource();
- ribSourcePanel->Title = "Bloques";
-
- RibbonPanel* ribPanel = new RibbonPanel;
- ribPanel->Source = ribSourcePanel;
- m_RibTab->Panels->Add( ribPanel );
-
- // Create a button
- RibbonButton* ribButton1 = new RibbonButton();
- ribButton1->Text = S"AddTE";
- ribButton1->Click += new Windows::RoutedEventHandler(this, &MyRibbonTabProxy:: OnAddTEClick);
- ribButton1->ShowText = true;
- RibbonRow* row = new RibbonRow();
- row->Items->Add(ribButton1);
- ribSourcePanel->Rows->Add( row );
- }
- void MyRibbonTabProxy:: OnAddTEClick(Object* sender, Windows::RoutedEventArgs *ea)
- {
- Autodesk::AutoCAD::ApplicationServices::Application:: DocumentManager
- ->MdiActiveDocument->SendStringToExecute(S"_AddTE ",false, false, false );
- }
-
- 2 - Using VS2008 for AutoCAD 2011:
-
- -- In stdafx.h add this lines:
- #using <mscorlib.dll>
- #using <System.dll>
- #using <acdbmgd.dll>
- #using <acmgd.dll>
- #using <AcCui.dll>
- #using <AdWindows.dll>
- #using <PresentationCore.dll>
- #using <PresentationFramework.dll>
- #using <WindowsBase.dll>
-
- #pragma once
- #include "StdAfx.h"
- using namespace System;
- using namespace Autodesk::Windows;
- void MakeIt(void);
-
- // The new implementation uses ICommand instead RoutedEventHandler
-
- public __gc class AutoCADCommandHandler: public ICommand
- {
- public:
- void remove_CanExecuteChanged(System::EventHandler* eh){};
- void add_CanExecuteChanged(System::EventHandler* eh){};
- AutoCADCommandHandler(){};
- bool CanExecute(Object* parameter);
- void Execute(Object* parameter);
- };
-
- public __gc class MyRibbonTabProxy
- {
- private:
- RibbonTab* m_RibTab;
- public:
- MyRibbonTabProxy(String* title, String* id );
- };
-
- void MakeIt()
- {
- MyRibbonTabProxy* rb = new MyRibbonTabProxy( S"CadOfiTec", S"CadOfiTecTab" );
- }
-
- bool AutoCADCommandHandler::CanExecute(Object* parameter)
- {
- return true;
- }
- void AutoCADCommandHandler::Execute(Object* parameter)
- {
- RibbonButton* ribBtn =
- static_cast<Autodesk::Windows::RibbonButton*> (parameter);
- Autodesk::AutoCAD::ApplicationServices::Application:: DocumentManager
- ->MdiActiveDocument->SendStringToExecute(
- static_cast<System:tring*>(ribBtn->CommandParameter), false, false, false );
- }
-
- MyRibbonTabProxy::MyRibbonTabProxy(String* title, String* id )
- {
- RibbonControl* ribCtrl = Autodesk::Windows::ComponentManager::Ribbon;
- if( ribCtrl == NULL )
- return;
- m_RibTab = ribCtrl->FindTab( id );
- if( m_RibTab != NULL )
- return;
- m_RibTab = new RibbonTab();
- m_RibTab->Title = title;
- m_RibTab->Id = id;
- ribCtrl->Tabs->Add( m_RibTab );
- m_RibTab->IsActive = true;
- // Create the panel source
- RibbonPanelSource* ribSourcePanel = new RibbonPanelSource();
- ribSourcePanel->Title = "Bloques";
-
- RibbonPanel* ribPanel = new RibbonPanel;
- ribPanel->Source = ribSourcePanel;
- m_RibTab->Panels->Add( ribPanel );
-
- // Create a button
- RibbonButton* ribButton1 = new RibbonButton();
- ribButton1->Text = S"AddTE";
- ribButton1->ShowText = true;
- AutoCADCommandHandler* ch = new AutoCADCommandHandler();
- ribButton1->CommandHandler = ch;
- ribSourcePanel->Items->Add( ribButton1 );
- }
不知vla-GetInterfaceObject 能否搞定。 |