Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Journal)
  • No Skin
Collapse
Brand Logo

D2P Community

  1. Home
  2. Categories
  3. Scripting / API
  4. Create a Cadwork material group using c++ API

Create a Cadwork material group using c++ API

Scheduled Pinned Locked Moved Scripting / API
3 Posts 1 Posters 203 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sus
    wrote on last edited by
    #1

    I am trying to create a new material group using the C++ Cadwork API.

    Using the UI, I would use the "new material group" button :
    c1621406-e22d-4972-bc17-b7481aca2432-image.png

    Is that function currently available in the API ?

    The ICwAPI3DMaterialController allows me to getGroup or setGroup but not createGroup.

    Thanks a lot,
    Sylvain

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sus
      wrote on last edited by
      #2

      Giving any free string in setGroup seems to do the trick. I still have an issue with the material name itself, will post a full snippet when solved.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sus
        wrote on last edited by
        #3

        Here is a snippet working for me

        	// convert string to wstring
        	std::wstring ToWideString(std::string narrowString)
        	{
        	    return std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(narrowString);
        	}
        
        
        	void CreateMaterial(CwAPI3D::MaterialController* mc) {
        		// get the string value of the material
        		auto newMaterialNameWS = ToWideString(Value);
        		auto newMaterialNameCS = newMaterialNameWS.c_str();
        		// check if the material exists
        		auto material_id = mc->getMaterialID(newMaterialNameCS);
        		
        		if (material_id == 0) {
        			// if the material does not exist, create it
        			material_id = mc->createMaterial(newMaterialNameCS);;
        			// set the material group to switchboard materials
        			mc->setGroup(material_id, L"Switchboard_Materials");
        		}
        	}
        
        
        
        1 Reply Last reply
        0

        • Login

        • Don't have an account? Register

        Powered by NodeBB Contributors
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups