Jump to content
Developer Wiki and Function Reference Links ×

How to get data of models?


Cachino King

Recommended Posts

I need to get some data of models such as mesh, textures, coordinates, etc. 

I found that there is a function that can iterate over all objects: VCOM:VectorWorks:ISDK::ForEachObject. Does this "object" contain all of the models in the scene? 

I noticed that this function used like this: 

gSDK->ForEachObject( allObjects | descendIntoAll, MyCallBack, & data );

So what kind of data can I get from this  "& data"? 

 

I also found these functions: VCOM:VectorWorks:ISDK::GetTexturesVCOM:VectorWorks:ISDK::GroupToMesh. Can these functions get the data what I want? 

Thank you! 

Link to comment
virtual void ForEachObject(
              short                     traverseWhat,
              GS_ForEachObjectProcPtr   action,
              void                      *actionEnv)

 

action is called for all object that match the traverseWhat criteria, you need to filter the type that you want in that function.

actionEnv can be used to pass on any kind of data you want from your "main" function to this action function.

Here's a rough example, this is how you could get a list of all lines in the drawing.

 

struct SMyLineData
{
	std::vector<MCObjectHandle> listLines;
};

void ApplyCritIsLine( Handle h, CallBackPtr, void *data )
{
	SMyLineData* lineData = (SMyLineData*)data;

	if ( gSDK->GetObjectTypeN( h ) == kLineNode )
		lineData->listLines.push_back( h );
}

void foo()
{
	// save all lines in the drawing in lineData.listLines
	SMyLineData lineData;
	gSDK->ForEachObject( allObjects | descendIntoAll, ApplyCritIsLine, &lineData );
	// do something with that list.
}

 

However, instead of saving it in a list, you could also do your operation directly in your action function.

 

For resources, like texture definitions, you need to use gSDK->BuildResourceListN() or any of the other resource list functions/classes.

 

But I'm not 100% sure this is actually what you need, do you want to go through the list of all objects inside a container?

  • Like 1
Link to comment

I need to live sync the VW scene to another software. So I need to get the data for all the models in the scene includes mesh,  textures, coordinates. And after some calculation VW scene should display on that software. So I just need to know the data of models. 

The scenes I need to synchronize should all be 3D scenes. I don't know how model data is stored, so I can't get such data I want.

Also I need to export some .fbx files of these model to make sure it can be used by other software. 

 

Thank you!

Link to comment

Wow, be aware this is a very difficult thing to do, it will take some time to implement this. In VW, you have all sort of 3D geometry, al with different ways of saving their data and graphical attributes. So you'll need to cover all cases... And every year things get added/changed in VW, so maintening this will take some time too.

I think it's best to contact VW inc for this, they might be able to tell you what other export menu commands do and tell you how to implement this correctly in a safe way.

@Hugues @Vlado @SteveJ

  • Like 1
Link to comment

Vectorworks is solids-based, not mesh-based, so if you need meshes you need to be doing object conversion, not just fetching object information. If you can use parasolids as your base data that might be easier. You can also automatically export various file formats via the SDK, but that won’t give you live updates. 
 

Are you doing this project as an end user or are you developing a commercial application?

  • Like 1
Link to comment
11 hours ago, JBenghiat said:

Vectorworks is solids-based, not mesh-based, so if you need meshes you need to be doing object conversion, not just fetching object information. If you can use parasolids as your base data that might be easier. You can also automatically export various file formats via the SDK, but that won’t give you live updates. 
 

Are you doing this project as an end user or are you developing a commercial application?

I develop this project for myself, this task is very important for me. It is related to my graduation project. 

 

I noticed that there is a option: "File -> Export -> Export FBX". But I didn't find it in the Class Reference. 

Is this function used the same way as VCOM:VectorWorks:Filing:IImportExport3DS::Export

Link to comment
3 hours ago, Pat Stanford said:

DoMenuTextByName('FBX Export',0); 

 

Will export an FBX file from Vectorscipt.   VS.DoMenuTextByName('FBX Export',0)  should work from Python but I didn't test.

 

But it won't work in the background as it always opens the settings dialog box.

Thank you. 

My project is completly coded by C++. Now I know that is difficult to export FBX directly. 

Link to comment

You can look at the supported SDK export file formats in Interface/Filing: STL, 3DS, DWG, OBJ, SAT, and SketchUp. I don't know how many of those can happen without issuing a settings dialog, though.

 

I would caution that live sync might be out of scope for a student project. Current live sync solutions have requited teams of developers, collaborating on both the export and import aide.

  • Like 1
Link to comment

@Cachino KingVectorworks Graphics Sync is what you want for a true live sync, assuming that you use VW2020 or higher.
Look at Interfaces\VectorWorks\IVGS.h, you will need an extra header file for ::VGS::Operation because it's not included in the normal SDK. You'd have to contact VW and ask for access to the API.
VGS is relatively straightforward, you get tessellated geometry, camera position, rudimentary materials (full materials with some more work), object instances and proper update events for all of it.
 

Alternatively there is the Tesselator that you can use to get geometry from objects and their children.

If you throw a layer handle into this tesselator it will export everything on that layer. The STessTraingle contains information about what is being tessellated and the object, material, triangles for it. Extra information like a transformation you can get from the object.

This is more of a one-time export and you would need to detect any changes in the document yourself and then tessellate those parts again, which I'm not sure how to do.

GS_TessellateIteratorProcPtr tesselationCallback = [](ETessProcReason reason, STessTraingle triangle, CallBackPtr cbp, void* pEnv)
{
  YourExportContext* context = static_cast<YourExportContext*>(pEnv);
  switch (reason)
  {
      // collect data into context
  }
};

YourExportContext context{};

TTesselator tesselator = gSDK->CreateTessellator(true);
VectorWorks::STesselateOptions tesselationOptions{};
MCObjectHandle handleToRecursivelyTesselate;
gSDK->TesselateObjectN(tesselator, tesselationOptions, handleToRecursivelyTesselate, tesselationCallback, &context);
gSDK->DeleteTessellator(tesselator);

 

Edited by JHangstoerfer
  • Like 2
Link to comment
13 hours ago, JBenghiat said:

I would caution that live sync might be out of scope for a student project. Current live sync solutions have requited teams of developers, collaborating on both the export and import aide.

Yeah, that's quite difficult for me. The functions that implement FBX export do not exist. 

I looked up the file "MockSDK.h" and found a funtion "GetMesh". After some test, this function can let me get the vertexs of the mesh, and I found normal data, uv data all in the class "IMeshData". 

I just need to get these data and some material data and send these to another software. This part is relatively simple. 

Maybe there are very few kinds of polygons can convert to mesh. But I think it's enough to finish this task. 

Link to comment
9 hours ago, JHangstoerfer said:

Vectorworks Graphics Sync is what you want for a true live sync, assuming that you use VW2020 or higher.
Look at Interfaces\VectorWorks\IVGS.h, you will need an extra header file for ::VGS::Operation because it's not included in the normal SDK. You'd have to contact VW and ask for access to the API.
VGS is relatively straightforward, you get tessellated geometry, camera position, rudimentary materials (full materials with some more work), object instances and proper update events for all of it.

VGS is too difficult to me. I just need some mesh data and material data and send to my program. Although vectorwork use solid-base to save model data, I still want to convert solid to mesh. And I found the function can implement this. 

I read some guidance documents of my task that live sync they said is actually dynamic updating. If the scene changes in VW, the model information needs to be retransmitted. This method doesn't sound nearly as efficient as VGS, but it's easier to implement. 

Link to comment
5 hours ago, Cachino King said:

Yeah, that's quite difficult for me. The functions that implement FBX export do not exist. 

I looked up the file "MockSDK.h" and found a funtion "GetMesh". After some test, this function can let me get the vertexs of the mesh, and I found normal data, uv data all in the class "IMeshData". 

I just need to get these data and some material data and send these to another software. This part is relatively simple. 

Maybe there are very few kinds of polygons can convert to mesh. But I think it's enough to finish this task. 

GetMesh only works for kMeshNode objects. It doesn't work for solids.

 

4 hours ago, Cachino King said:

VGS is too difficult to me. I just need some mesh data and material data and send to my program. Although vectorwork use solid-base to save model data, I still want to convert solid to mesh. And I found the function can implement this. 

I read some guidance documents of my task that live sync they said is actually dynamic updating. If the scene changes in VW, the model information needs to be retransmitted. This method doesn't sound nearly as efficient as VGS, but it's easier to implement. 

Where are you having troubles with VGS? I think it's the easiest of any of these methods. You get meshes for all objects including solids via VGS and their materials in easy to use formats. I can answer any questions you got about VGS.

  • Like 1
Link to comment
33 minutes ago, JHangstoerfer said:

GetMesh only works for kMeshNode objects. It doesn't work for solids.

I used GroupToMesh first,then It crashes when it running to GetMesh. 

I used GetObjectType and found the object type is 40. 

The sheet of GetObjectType: kMeshNode  40  3D mesh object.

33 minutes ago, JHangstoerfer said:

Where are you having troubles with VGS? I think it's the easiest of any of these methods. You get meshes for all objects including solids via VGS and their materials in easy to use formats. I can answer any questions you got about VGS.

Thank you very much!

There is too little documentation related to VGS, and I just found this: SDK:Using the VGS API for Vectorworks model export and live sync

I tried to download the VGS Sample, but I didn't know how to use it. After I put those two files in the "Plug-Ins", I didn't see anything about VGS in the "Tools --> Workspaces --> Edit Workspace". 

 

Link to comment

Okay, I just found the VGS plugin. 

But I still don't understand why the GetMesh will cause my program crashed. 

//this function used like this:
/*
gSDK->ForEachObject(allObjects | descendIntoAll, CollectMesh, this);
*/

void CollectMesh(Handle h, CallBackPtr cbp, void* env) {
	// convert solid to 3DPolygons
	Handle meshH = gSDK->ConvertTo3DPolygons(h);
	// convert polygons to mesh
	short meshErrorType = gSDK->GroupToMesh(meshH);

	if (meshErrorType == 0)
	{
		VectorWorks::IMeshData **thisMesh;
		bool isGetMesh = gSDK->GetMesh(meshH, thisMesh);///crashed here

		//(**thisMesh).GetVertexPosition(vertexNum - 2, vertexs);
	}
}

 

Link to comment
  • Vectorworks, Inc Employee

@Cachino King It looks like you need to you use the ISDK function:

gSDK->TesselateObject

 

It will give you the faces and texture mapping of the object you provide. Essentially, it's like rendering the object, only it renders into a callback.

 

Send me an email to vstanev@vectorworks.net and I can send you some code snippets.

  • Like 1
Link to comment
On 2/24/2022 at 4:59 AM, Cachino King said:
VectorWorks::IMeshData **thisMesh;
		bool isGetMesh = gSDK->GetMesh(meshH, thisMesh);///crashed here

To answer your specific question, you want to pass the address of the pointer, rather than defining a double pointer

VectorWorks::IMeshDataPtr	thisMesh;
bool isGetMesh = gSDK->GetMesh( meshH, & thisMesh );

 

  • Like 1
Link to comment
  • Vectorworks, Inc Employee

Here is a little random information on textures and images.

 

Textures can be taken from the shaders:

https://developer.vectorworks.net/index.php/SDK:Using_Shader_Records&nbsp;

 

As for the images itself, there is a class

VWFC::VWObjects::VWBitmapObj

but I’m not sure how useful it is.

 

I would rather look into VCOM interface VectorWorks::Imaging::ICompressedImage for example. See the others in this namespace

They are located in the SDK, and automatically/should be included in your project:

\SDKLib\Include\Interfaces\VectorWorks\Imaging

 

You can use it like this:

using namespace VectorWorks::Imaging;

ICompressedImagePtr image( IID_CompressedImage ); // create an instance

Image->CreateFromObject( h );

 

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...