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 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; } } }