Rotating all geometry on a sketch

Rotating all geometry on a sketch

dinomyar
Enthusiast Enthusiast
767 Views
5 Replies
Message 1 of 6

Rotating all geometry on a sketch

dinomyar
Enthusiast
Enthusiast

I am tring to create some code that will rotate all the geometry on a sketch. I have tried the following, but it does nothing. I have a feeling that it is due to no geometry being in the ObjectCollection. What is the best way to get an object collection of all sketch entities? Would I have to loop through the lines, arcs, circles, etc collections and add each edge individually to the collection? Also, is there a place I can get more C++ samples, as VB does not show all the steps needed to use the API in C++?

 

CComPtr<SelectSet> selectset;

tmpdoc->get_SelectSet(&selectset);

selectset->Select(sketch);

CComPtr<ObjectCollection> objcollection;

CComVariant objenumvar(selectset);

transobj->CreateObjectCollection(objenumvar, &objcollection);

CComPtr<ObjectsEnumerator> objenum;

CComPtr<Point2d> center;

transgeom->CreatePoint2d(0.0, 0.0, &center);

sketch->RotateSketchObjects(objcollection, center, appdata.m_rotation, VARIANT_FALSE, VARIANT_FALSE, &objenum);

0 Likes
768 Views
5 Replies
Replies (5)
Message 2 of 6

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

We don't have many C++ samples as the majority of developers use other languages, and also the usage of the Inventor COM API from C++ is not specifc to Inventor. If you know how to use other COM libraries (Microsoft Word, AutoCAD, etc) then you should be able to use the Inventor COM library as well.

If you just need a skeleton C++ project or something to get you started, then have a look at the SDK C++ sample projects: "C:\Users\Public\Documents\Autodesk\Inventor 2017\SDK\DeveloperTools\Samples\VC++" 

 

Yes, definitely you'll have to add objects to the collection in order to specify which objects you want to rotate. Have just written an article that should be useful:
http://adndevblog.typepad.com/manufacturing/2016/05/rotate-sketch-entities.html

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 3 of 6

dinomyar
Enthusiast
Enthusiast

That sample helped. Thanks.

 

But for the issue with trying to use VB samples for creating VC code it is nearly impossible to determine how to make it work. For example, there is a sample program called "Extrude Feature - Create Block with Pocket API Sample" in the help file. In there is code 

 

Set oProfile = oSketch.Profiles.AddForSolid

 

which passes no parameters to the function. In VC, that function requires 3 parameters and a return parameter as so

 

HRESULT AddForSolid (VARIANT_BOOL Combine, const VARIANT & ProfilePathSegments,const VARIANT & Reserved, struct Profile * * _result = 0 );

 

Figuring out what is needed is not very intuitive. Calling it without any parameters like so

 

CoilSketch->GetProfiles()->AddForSolid(VARIANT_TRUE, vtMissing, vtMissing, &profile);

 

doesnt work, so I have to figure out what to pass. VB shortcuts this and makes it hard to figure out how to use the API without good VC samples.

 

 

0 Likes
Message 4 of 6

adam.nagy
Autodesk Support
Autodesk Support

If you search the C++ samples then you'll find that there is a sample "C:\Users\Public\Documents\Autodesk\Inventor 2017\SDK\DeveloperTools\Samples\VC++\AddIns\loftWithRailings" which is using the AddForSolid function.

Please give that a try.



Adam Nagy
Autodesk Platform Services
0 Likes
Message 5 of 6

dinomyar
Enthusiast
Enthusiast

I have looked at that sample, and have tried to use the AddForSolid the same way, i.e.

CComPtr<Profile> profile;

hResult= pProfiles->AddForSolid(TRUE, vtMissing, vtMissing, &pProfile);

but in my code it always fails, returning

Profiles::AddForSolid returned E_INVALIDARG One or more arguments are invalid.

Why could it fail in my code? What could be different that can cause it to fail? I have compared the code between the two add-ins and I am not doing anything different, just different geometry created on the sketches.

0 Likes
Message 6 of 6

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

Have a look at the C++ sample "C:\Users\Public\Documents\Autodesk\Inventor 2017\SDK\DeveloperTools\Samples\VC++\Standalone Applications\Inventor\SimpleExe"

 

If I add this code to that and before running it I select a sketch in the UI which has geometry in it that can be used as a profile, then it succeeds.

 

// SimpleExe.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"

// Main. Note that all COM related activity (including the automatic 'release' within smart
// pointers) MUST take place BEFORE CoUnitialize(). Hence the function 'block' within which
// the smart-pointers construct and destruct (and AddRef and Release) keeping the CoUnitialize
// safely out of the way.

static HRESULT AddForSolid()
{
	HRESULT Result = NOERROR;

	CLSID InvAppClsid;
	Result = CLSIDFromProgID(L"Inventor.Application", &InvAppClsid);
	if (FAILED(Result)) return Result;

	CComPtr pInvAppUnk;
	
	Result = ::GetActiveObject(InvAppClsid, NULL, &pInvAppUnk);
	if (FAILED(Result))
		_tprintf_s(_T("*** Could not get hold of an active Inventor application ***\n"));

	if (FAILED(Result)) return Result;

	CComPtr invApp;
	Result = pInvAppUnk->QueryInterface(__uuidof(Application), (void **)&invApp);
	if (FAILED(Result)) return Result;

	CComQIPtr tmpdoc = invApp->GetActiveDocument();
	CComPtr selectset = tmpdoc->GetSelectSet();
	CComQIPtr sketch = selectset->GetItem(1);
	CComPtr profiles = sketch->GetProfiles();
	CComPtr profile;
	Result = profiles->AddForSolid(TRUE, vtMissing, vtMissing, &profile);
	
	return S_OK;
}

int _tmain(int argc, _TCHAR* argv[])
{
	HRESULT Result = NOERROR;

	Result = CoInitialize(NULL);

	if (SUCCEEDED(Result))
		Result = AddForSolid();

	CoUninitialize();

	return 0;
}

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes