private bool IsMetal(Asset appearance) { // TODO: Figure out how to identify appearance types so this isn't neccecary try { return(((BooleanAssetValue)appearance["generic_is_metal"]).Value); } catch {} try { var _ = ((ColorAssetValue)appearance["metal_color"]).Value; return(true); } catch {} try { var _ = ((ColorAssetValue)appearance["metallicpaint_base_color"]).Value; return(true); } catch {} return(false); }
private MaterialBuilder ExportAppearanceCached(Asset appearance) { if (!exportMaterials || appearance == null) { return(defaultMaterial); } var appearanceName = appearance.Name; if (materialCache.ContainsKey(appearanceName)) { return(materialCache[appearanceName]); } var colorVector = Vector4.One; try { Color tempColor = AttemptGetColor(appearance); colorVector = new Vector4(tempColor.Red / 255f, tempColor.Green / 255f, tempColor.Blue / 255f, (float)tempColor.Opacity); } catch { } var isMetal = IsMetal(appearance); var metallicFactor = isMetal ? 1f : 0f; var material = new MaterialBuilder() .WithMetallicRoughnessShader() .WithChannelParam("BaseColor", colorVector) .WithChannelParam("MetallicRoughness", new Vector4(metallicFactor, 1, 0, 0)); // btw metallic isn't getting applied for some reason // TODO: metallic and roughness materialCache[appearanceName] = material; return(material); }
private Color AttemptGetColor(Asset appearance) { // TODO: Figure out how to identify appearance types so this isn't neccecary try { return(((ColorAssetValue)appearance["generic_diffuse"]).Value); } catch {} try { return(((ColorAssetValue)appearance["masonrycmu_color"]).Value); } catch {} try { return(((ColorAssetValue)appearance["solidglass_transmittance_custom_color"]).Value); } catch {} try { return(((ColorAssetValue)appearance["hardwood_tint_color"]).Value); } catch {} try { return(((ColorAssetValue)appearance["water_tint_color"]).Value); } catch {} try { return(((ColorAssetValue)appearance["concrete_color"]).Value); } catch {} try { return(((ColorAssetValue)appearance["plasticvinyl_color"]).Value); } catch {} try { return(((ColorAssetValue)appearance["metallicpaint_base_color"]).Value); } catch {} try { return(((ColorAssetValue)appearance["wallpaint_color"]).Value); } catch {} try { return(((ColorAssetValue)appearance["metal_color"]).Value); } catch {} try { return(((ColorAssetValue)appearance["ceramic_color"]).Value); } catch {} try { return(((ColorAssetValue)appearance["glazing_transmittance_map"]).Value); } catch {} throw new Exception("Could not get color!"); }
private static void PrintAsset(Asset appearance, StreamWriter file) { // file.Write("Appearance,"); // file.Write("DisplayName,"); // file.Write("Name,"); file.Write(appearance.DisplayName + ","); // file.Write(" HasTexture: " + appearance.HasTexture); // file.Write(" IsReadOnly: " + appearance.IsReadOnly); file.Write(appearance.Name + ","); file.WriteLine(); foreach (AssetValue o in appearance) { PrintAssetValue(o, file); } file.WriteLine(); file.WriteLine(); }
public void AddOrRemoveFromGroup(bool add) { if (_invApp.Documents.Count == 0) { MessageBox.Show("Need to open an Assembly document"); return; } if (_invApp.ActiveDocument.DocumentType != DocumentTypeEnum.kAssemblyDocumentObject) { MessageBox.Show("Need to have an Assembly document active"); return; } AssemblyDocument asmDoc = default(AssemblyDocument); asmDoc = (AssemblyDocument)_invApp.ActiveDocument; if (asmDoc.SelectSet.Count == 0) { MessageBox.Show("Need to select a Part or Sub Assembly"); return; } SelectSet selSet = default(SelectSet); selSet = asmDoc.SelectSet; Inventor.Assets colour = asmDoc.Assets; try { ComponentOccurrence compOcc = default(ComponentOccurrence); object obj = null; foreach (object obj_loopVariable in selSet) { obj = obj_loopVariable; compOcc = (ComponentOccurrence)obj; System.Diagnostics.Debug.Print(compOcc.Name); AttributeSets attbSets = compOcc.AttributeSets; if (add) { // Add the attributes to the ComponentOccurrence if (!attbSets.NameIsUsed["myPartGroup"]) { AttributeSet attbSet = attbSets.Add("myPartGroup"); Inventor.Attribute attb = attbSet.Add("PartGroup1", ValueTypeEnum.kStringType, "Group1"); Inventor.Asset asset = asmDoc.Assets["Red"]; compOcc.Appearance = asset; } } else { // Delete the attributes to the ComponentOccurrence if (attbSets.NameIsUsed["myPartGroup"]) { attbSets["myPartGroup"].Delete(); } } //compOcc.Visible = False } } catch (Exception ex) { MessageBox.Show("Is the selected item a Component?"); MessageBox.Show(ex.ToString()); return; } }
private void DebugPrintAppearance(Asset appearance) { Debug.Print("=========================+"); Debug.Print(appearance.Name); Debug.Print(appearance.DisplayName); Debug.Print(appearance.CategoryName); foreach (AssetValue assetValue in appearance) { Debug.Print("--------------"); Debug.Print(assetValue.Name); Debug.Print(assetValue.DisplayName); switch (assetValue.ValueType) { case AssetValueTypeEnum.kAssetValueTypeColor: var colorAssetValue = (ColorAssetValue)assetValue; if (colorAssetValue.HasMultipleValues) { foreach (var value in colorAssetValue.get_Values()) { Debug.Print(value.Red.ToString()); Debug.Print(value.Green.ToString()); Debug.Print(value.Blue.ToString()); Debug.Print(value.Opacity.ToString()); } } else { Debug.Print(colorAssetValue.Value.Red.ToString()); Debug.Print(colorAssetValue.Value.Green.ToString()); Debug.Print(colorAssetValue.Value.Blue.ToString()); Debug.Print(colorAssetValue.Value.Opacity.ToString()); } break; case AssetValueTypeEnum.kAssetValueTypeBoolean: var booleanAssetValue = (BooleanAssetValue)assetValue; Debug.Print(booleanAssetValue.Value.ToString()); break; case AssetValueTypeEnum.kAssetValueTypeChoice: var choiceAssetValue = (ChoiceAssetValue)assetValue; Debug.Print(choiceAssetValue.Value); break; case AssetValueTypeEnum.kAssetValueTypeFloat: var floatAssetValue = (FloatAssetValue)assetValue; if (floatAssetValue.HasMultipleValues) { foreach (var value in floatAssetValue.get_Values()) { Debug.Print(value.ToString()); } } else { Debug.Print(floatAssetValue.Value.ToString()); } break; case AssetValueTypeEnum.kAssetValueTypeInteger: var integerAssetValue = (IntegerAssetValue)assetValue; if (integerAssetValue.HasMultipleValues) { foreach (var value in integerAssetValue.get_Values()) { Debug.Print(value.ToString()); } } else { Debug.Print(integerAssetValue.Value.ToString()); } break; case AssetValueTypeEnum.kAssetValueTypeString: var stringAssetValue = (StringAssetValue)assetValue; Debug.Print(stringAssetValue.Value); break; } } }