internal CompDef( SU.ComponentDefinitionRef componentDefinitionRef) { // Get the name. SU.StringRef stringRef = new SU.StringRef(); SU.StringCreate(stringRef); SU.ComponentDefinitionGetName(componentDefinitionRef, stringRef); Name = Convert.ToStringAndRelease(stringRef); // Get the description. stringRef = new SU.StringRef(); SU.StringCreate(stringRef); SU.ComponentDefinitionGetDescription(componentDefinitionRef, stringRef); Description = Convert.ToStringAndRelease(stringRef); // Get the entities. SU.EntitiesRef entitiesRef = new SU.EntitiesRef(); SU.ComponentDefinitionGetEntities(componentDefinitionRef, entitiesRef); //entities = new Entities(entitiesRef); UnpackEntities(entitiesRef); }
internal Material(SU.MaterialRef suMaterialRef) { // Get the name. SU.StringRef suStringRef = new SU.StringRef(); SU.StringCreate(suStringRef); SU.MaterialGetNameLegacyBehavior(suMaterialRef, suStringRef); Name = Convert.ToStringAndRelease(suStringRef); // Get the types. SU.MaterialGetType(suMaterialRef, out suMaterialType); SU.MaterialGetColorizeType(suMaterialRef, out suMaterialColorizeType); // Get the color and/or texture. SU.Color suColor; SU.TextureRef suTextureRef; switch (suMaterialType) { case SU.MaterialType_Colored: SU.MaterialGetColor(suMaterialRef, out suColor); Color = new Color(suColor); break; case SU.MaterialType_Textured: suTextureRef = new SU.TextureRef(); SU.MaterialGetTexture(suMaterialRef, suTextureRef); Texture = new Texture(suTextureRef); break; case SU.MaterialType_ColorizedTexture: SU.MaterialGetColor(suMaterialRef, out suColor); Color = new Color(suColor); suTextureRef = new SU.TextureRef(); SU.MaterialGetTexture(suMaterialRef, suTextureRef); Texture = new Texture(suTextureRef); break; default: throw new Exception($"Unknown material type = {suMaterialType}"); } }
public static string ToStringAndRelease(SU.StringRef suStringRef) { string convertedString = ToString(suStringRef); SU.StringRelease(suStringRef); return(convertedString); }
internal Face(SU.FaceRef suFaceRef) { // Get its UVHelper for texture-mapping coordinates. UVHelper uvh = new UVHelper(suFaceRef); // Get the outer loop. EdgePointList edgePointList = new EdgePointList(suFaceRef); uvh.Assign(edgePointList); outerLoop = new Loop(edgePointList).edgePoints; // Get any inner loops. SU.FaceGetNumInnerLoops(suFaceRef, out long count); SU.LoopRef[] loopRefs = new SU.LoopRef[count]; long len = count; SU.FaceGetInnerLoops(suFaceRef, len, loopRefs, out count); foreach (SU.LoopRef loopRef in loopRefs) { innerLoops.Add( new Loop(new EdgePointList(loopRef)).edgePoints); } SU.MaterialRef suMaterialRef = new SU.MaterialRef(); try { SU.FaceGetFrontMaterial(suFaceRef, suMaterialRef); SU.StringRef suStringRef = new SU.StringRef(); SU.StringCreate(suStringRef); SU.MaterialGetNameLegacyBehavior(suMaterialRef, suStringRef); MaterialName = Convert.ToStringAndRelease(suStringRef); } catch (SketchUpException e) { if (e.ErrorCode == SU.ErrorNoData) { // Not an error. It just has no material. } else { throw; } } }
public static string ToString(SU.StringRef suStringRef) { // We could add code to the API wrapper and use // the String(char*) constructor, because the C // API's SUStringRef is just a pointer to a buffer // full of Unicode. But that would be programming // to the implementation, not the interface, and // the C API is still changing. We will use this // more cumbersome method to be on the safe side. long length; SU.StringGetUTF8Length(suStringRef, out length); byte[] buff = new byte[length]; SU.StringGetUTF8( suStringRef, buff.Length, buff, out length); return(Encoding.UTF8.GetString(buff, 0, buff.Length)); }
internal Group( SU.GroupRef groupRef) { // Get the transform. SU.Transformation transformation = new SU.Transformation(); SU.GroupGetTransform(groupRef, out transformation); Transform = new Transform(transformation); // Get the name. SU.StringRef stringRef = new SU.StringRef(); SU.StringCreate(stringRef); SU.GroupGetName(groupRef, stringRef); Name = Convert.ToStringAndRelease(stringRef); // Note that a Group can upcast into a DrawingElement. // As such, it can have an instance-wide Material set for it that // SketchUp will use on any Faces that use the defalt Material. // But you cannot set the Group's material; you must // upcast first. // Upcast to a DrawingElement and get the material name. SU.DrawingElementRef drawingElementRef = SU.GroupToDrawingElement(groupRef); SU.MaterialRef materialRef = new SU.MaterialRef(); try { SU.DrawingElementGetMaterial(drawingElementRef, materialRef); stringRef = new SU.StringRef(); SU.StringCreate(stringRef); SU.MaterialGetNameLegacyBehavior(materialRef, stringRef); MaterialName = Convert.ToStringAndRelease(stringRef); } catch (SketchUpException e) { if (e.ErrorCode == SU.ErrorNoData) { // Not an error. It just has no material. } else { throw; } } // Get the entities. SU.EntitiesRef entitiesRef = new SU.EntitiesRef(); SU.GroupGetEntities(groupRef, entitiesRef); UnpackEntities(entitiesRef); }
internal CompInst(SU.ComponentInstanceRef instanceRef) { // Get the transform. SU.Transformation transformation = new SU.Transformation(); SU.ComponentInstanceGetTransform(instanceRef, out transformation); Transform = new Transform(transformation); // Get the instance name. SU.StringRef stringRef = new SU.StringRef(); SU.StringCreate(stringRef); SU.ComponentInstanceGetName(instanceRef, stringRef); InstanceName = Convert.ToStringAndRelease(stringRef); // Get the definition name. SU.ComponentDefinitionRef componentDefinitionRef = new SU.ComponentDefinitionRef(); SU.ComponentInstanceGetDefinition(instanceRef, componentDefinitionRef); stringRef = new SU.StringRef(); SU.StringCreate(stringRef); SU.ComponentDefinitionGetName(componentDefinitionRef, stringRef); ComponentName = Convert.ToStringAndRelease(stringRef); // Note that a ComponentInstance can upcast into a DrawingElement. // As such, it can have an instance-wide Material set for it that // SketchUp will use on any Faces that use the defalt Material. // But you cannot set the ComponentInstance's material; you must // upcast first. // Upcast to a DrawingElement and get the material name. SU.DrawingElementRef drawingElementRef = SU.ComponentInstanceToDrawingElement(instanceRef); SU.MaterialRef materialRef = new SU.MaterialRef(); try { SU.DrawingElementGetMaterial(drawingElementRef, materialRef); stringRef = new SU.StringRef(); SU.StringCreate(stringRef); SU.MaterialGetNameLegacyBehavior(materialRef, stringRef); MaterialName = Convert.ToStringAndRelease(stringRef); } catch (SketchUpException e) { if (e.ErrorCode == SU.ErrorNoData) { // Not an error. It just has no material. } else { throw; } } }