Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding menu in AutoCAD through ARX

553 views
Skip to first unread message

Gaurav

unread,
Jan 21, 2004, 4:52:01 AM1/21/04
to
hi all,

i am trying to add a menu in AutoCAD through the coding done in VC++ for ARX object.

what i need to do is: the menu should be added to the menu bar as soon as i load the arx object in AutoCAD and not after i enter a command at the prompt...

i will be really thankful if anyone can help me out in this.

i have done the programming, but at present the menu is added after writing the command at the prompt. where exactly should i write the code so tht the above query is solved ?

thank you all for reading this query,
Gaurav Shah...

Zatopek

unread,
Jan 21, 2004, 5:20:28 AM1/21/04
to
Try making a MNL file with the same name as the MNU-file. This is loaded
when the menu are loaded.

Just one line is required to insert your menu at POP10.

(menucmd "P10=+MyMenuGroup.POP10")


"Gaurav" <nos...@address.withheld> wrote in message
news:15400008.1074678752872.JavaMail.javamailuser@localhost...

Gaurav

unread,
Jan 21, 2004, 5:41:21 AM1/21/04
to
dear Zatopek,

thanks a lot for ur reply.

but i dont want to add the menu manually in the txt file, this process should take place through coding. kindly reply if u have any idea for it.

again thanks a lot for your kind attention.

regards,
Gaurav..

Zatopek

unread,
Jan 21, 2004, 5:49:22 AM1/21/04
to
Try acedMenuCmd
Don't know if this can do it, but have a try.

"Calling acedMenuCmd() and passing "P1=test.numeric" assigns POP menu 12 to
POP menu 2, assuming that the following menu file definitions exist. "

"Gaurav" <nos...@address.withheld> wrote in message

news:8219993.107468171...@jiveforum1.autodesk.com...

MrK

unread,
Jan 21, 2004, 11:07:01 PM1/21/04
to
Hi,
Using ActiveX Automation interfaces we can add menu items into the
AutoCAD.
see example which is available in
\ObjectArx\docsamps\comsamps\AsdkMfcComSamp.
that sample Code Is

void addMenuThroughCom()
{
AutoCAD::IAcadApplication *pAcad;
AutoCAD::IAcadMenuBar *pMenuBar;
AutoCAD::IAcadMenuGroups *pMenuGroups;
AutoCAD::IAcadMenuGroup *pMenuGroup;
AutoCAD::IAcadPopupMenus *pPopUpMenus;
AutoCAD::IAcadPopupMenu *pPopUpMenu;
AutoCAD::IAcadPopupMenuItem *pPopUpMenuItem;

HRESULT hr = NOERROR;
CLSID clsid;
LPUNKNOWN pUnk = NULL;
LPDISPATCH pAcadDisp = NULL;

hr = ::CLSIDFromProgID(L"AutoCAD.Application", &clsid);

if (SUCCEEDED(hr))
{
if(::GetActiveObject(clsid, NULL, &pUnk) == S_OK)
{
if (pUnk->QueryInterface(IID_IDispatch, (LPVOID*)
&pAcadDisp) != S_OK)
return;
pUnk->Release();
}
}

if (SUCCEEDED(pAcadDisp->QueryInterface
(AutoCAD::IID_IAcadApplication,(void**)&pAcad))) {
pAcad->put_Visible(true);
}
else
{
acutPrintf("\nQueryInterface trouble.");
return;
}

pAcad->get_MenuBar(&pMenuBar);
pAcad->get_MenuGroups(&pMenuGroups);
pAcad->Release();

long numberOfMenus;
pMenuBar->get_Count(&numberOfMenus);
pMenuBar->Release();

VARIANT index;
VariantInit(&index);

V_VT(&index) = VT_I4;
V_I4(&index) = 0;
pMenuGroups->Item(index, &pMenuGroup);
pMenuGroups->Release();

pMenuGroup->get_Menus(&pPopUpMenus);
pMenuGroup->Release();

WCHAR wstrMenuName[256];
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, "AsdkComAccess",
-1, wstrMenuName, 256);

if (!bIsMenuLoaded) {
pPopUpMenus->Add(wstrMenuName, &pPopUpMenu);
if (pPopUpMenu != NULL) {
pPopUpMenu->put_Name(wstrMenuName);
WCHAR wstrMenuItemName[256];
MultiByteToWideChar(CP_ACP, 0,"&Add A ComCircle",
-1, wstrMenuItemName, 256);

WCHAR wstrMenuItemMacro[256];
MultiByteToWideChar(CP_ACP, 0, "AsdkComCircle ",
-1, wstrMenuItemMacro, 256);

VariantInit(&index);
V_VT(&index) = VT_I4;
V_I4(&index) = 0;

pPopUpMenu->AddMenuItem(index, wstrMenuItemName,
wstrMenuItemMacro, &pPopUpMenuItem);

VariantInit(&index);
V_VT(&index) = VT_I4;
V_I4(&index) = 1;

pPopUpMenu->AddSeparator(index,&pPopUpMenuItem);
MultiByteToWideChar(CP_ACP, 0,"Auto&LISP Example", -1,
wstrMenuItemName, 256);

MultiByteToWideChar(CP_ACP, 0,"(prin1 \"Hello\") ", -1,
wstrMenuItemMacro, 256);

VariantInit(&index);
V_VT(&index) = VT_I4;
V_I4(&index) = 2;
pPopUpMenu->AddMenuItem(index, wstrMenuItemName,
wstrMenuItemMacro, &pPopUpMenuItem);

VariantInit(&index);

V_VT(&index) = VT_I4;
V_I4(&index) = numberOfMenus - 2;;
pPopUpMenu->InsertInMenuBar(index);
pPopUpMenu->Release();

pPopUpMenuItem->Release();
bIsMenuLoaded = true;
} else {
acutPrintf("\nMenu not created.");
}
} else {
VariantInit(&index);
V_VT(&index) = VT_BSTR;
V_BSTR(&index) = wstrMenuName;
pPopUpMenus->RemoveMenuFromMenuBar(index);
bIsMenuLoaded = false;

}
pPopUpMenus->Release();
}


regards
M Ram Kumar.
Chennai.

"Zatopek" <zat...@viasys.se> wrote in message news:<400e5936_3@newsprd01>...

Gaurav

unread,
Jan 22, 2004, 12:08:58 AM1/22/04
to
hey Zatopek,

i tried doing the process using acedMenuCmd().
but its not working. can u suggest any other method for adding the menu into the menu bar as soon as i load my ARX. it shud not get added when i start AutoCAD, but only after i load my ARX object.

thanks a lot for ur kind attension.
Gaurav

vladdygo

unread,
Jan 22, 2004, 4:10:16 AM1/22/04
to
TRY:

IAcadMenuGroup *mnuGrp = NULL;
if (!getAcadMenuGroup(&mnuGrp)) return ;

//now get all the popup menus
IAcadPopupMenus *mnus = NULL;
HRESULT hr = S_OK;
hr = mnuGrp->get_Menus(&mnus);
long cnt;

VARIANT vtIndex2;
IAcadPopupMenu *polyMnu2 = NULL;
hr = mnus->Add(L"My menu", &polyMnu2);

mnus->get_Count(&cnt);
vtIndex2.lVal = cnt;

vtIndex2 = 10; //menu number - but it didn't worked...don't now why it
apears as 1st menu
mnus->InsertMenuInMenuBar(L"My menu", vtIndex2 );

mnuGrp->Release();
mnus->Release();

Anyway, see Polysamp example!
QUESTION: Does someone know how can I insert my bitmap on a Toolbar from
some resource inside my prroject? (Without calling ->Set), or how can I make
a bitmap resource dll?

Vladdygo.

Helio Santana

unread,
Jan 22, 2004, 7:05:22 AM1/22/04
to
Hi,
you should see "Create menus using ObjectARX", ID 72624 in ADN's web
http://adn.autodesk.com/techsupp/solutions/72624.htm

Have fun,
Helio Santana

"Gaurav" <nos...@address.withheld> escribió en el mensaje
news:15400008.1074678752872.JavaMail.javamailuser@localhost...

Gaurav

unread,
Jan 27, 2004, 12:52:09 AM1/27/04
to
hey Vladdygo,

thankz a lot for ur help...
i got a clue from it and did the required job...

Gaurav

unread,
Jan 27, 2004, 12:55:42 AM1/27/04
to
hey everyone,

now i am facing a new problem, i have added the menu in AutoCAD through ObjectARX code in VC++ but now i need to add a submenu items to one of the option in the menu, for which i dont have any clue....can anyone please help me out from this ? thanks a lot to everyone for readng this query.

waiting for a clue,
Gaurav.

vladdygo

unread,
Jan 28, 2004, 2:54:46 AM1/28/04
to
someMenu->AddSubMenu(...
someMenu->AddSeparator(...
someMenu->AddMenuItem(...

SEE "polysamp" sample !!!!

But, my advice : create a *.mnu file - it may contain all menus & toolbars
you want, including bitmaps for toolbars (wich reside in an external bitmap
resource dll. The dll must be named exactly the same with mnu file name, &
<Ing Bernd Cuder helped me on that> bitmap names must be like
"mybitmap16" -where mybitmap16 is your res bmp name).

This metod is easyer. If yo want to build your toolbars from arx : surprise
: you CAN'T put bitmaps on them (except bmp's on hdd...). With menus it
works.

"Gaurav" <nos...@address.withheld> wrote in message

news:32724102.107518297...@jiveforum1.autodesk.com...

0 new messages