Skip to content

Commit

Permalink
AddInstanceParam and AddTypeParam are added. (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
lotaked authored Oct 11, 2023
1 parent 1412e3d commit 168173a
Show file tree
Hide file tree
Showing 33 changed files with 516 additions and 759,547 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions src/ConsoleConnector/Commands/AddInstanceParamCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.DataExchange.ConsoleApp.Commands.Options;
using Autodesk.DataExchange.ConsoleApp.Helper;
using Autodesk.DataExchange.ConsoleApp.Interfaces;
using Autodesk.DataExchange.DataModels;

namespace Autodesk.DataExchange.ConsoleApp.Commands
{
internal class AddInstanceParamCommand : AddParamCommand
{
public AddInstanceParamCommand(IConsoleAppHelper consoleAppHelper) : base(consoleAppHelper)
{
this.IsInstanceParameter = true;
this.Name = "AddInstanceParameter";
Description = "Add instance parameters to element.";
}

public AddInstanceParamCommand(AddInstanceParamCommand addTypeParamCommand) : base(addTypeParamCommand)
{
this.IsInstanceParameter = addTypeParamCommand.IsInstanceParameter;
}

public override Command Clone()
{
return new AddInstanceParamCommand(this);
}
}
}
81 changes: 81 additions & 0 deletions src/ConsoleConnector/Commands/AddParamCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.DataExchange.ConsoleApp.Commands.Options;
using Autodesk.DataExchange.ConsoleApp.Helper;
using Autodesk.DataExchange.ConsoleApp.Interfaces;
using Autodesk.DataExchange.DataModels;

namespace Autodesk.DataExchange.ConsoleApp.Commands
{
internal abstract class AddParamCommand : Command
{
public bool IsInstanceParameter = false;
public AddParamCommand(IConsoleAppHelper consoleAppHelper) : base(consoleAppHelper)
{
Options = new List<CommandOption>
{
new ExchangeTitle(),
new ElementId(),
new ParameterName(),
new ParameterValue(),
new ParameterValueDataType()
};
}

public AddParamCommand(AddParamCommand addParamCommand) : base(addParamCommand)
{
}

public override Task<bool> Execute()
{
if (this.ValidateOptions() == false)
{
Console.WriteLine("Invalid inputs!!!");
return Task.FromResult(false);
}

var exchangeTitle = this.GetOption<ExchangeTitle>();
var elementId = this.GetOption<ElementId>();
var parameterName = this.GetOption<ParameterName>();
var parameterValue = this.GetOption<ParameterValue>();
var parameterValueType = this.GetOption<ParameterValueDataType>();
var exchangeData = ConsoleAppHelper.GetExchangeData(exchangeTitle.Value);
if (exchangeData == null)
{
Console.WriteLine("Exchange data not found.\n");
return Task.FromResult(false);
}

var elementDataModel = ElementDataModel.Create(ConsoleAppHelper.GetClient(), exchangeData);
var element = elementDataModel.Elements.ToList().FirstOrDefault(n => n.Id == elementId.Value);
if (element == null)
{
Console.WriteLine("Element not found");
return Task.FromResult(false);
}

DataModels.Parameter parameter = null;
if (parameterName.Value != null)
parameter = ConsoleAppHelper.GetParameterHelper().AddBuiltInParameter(element, parameterName.Value.Value, parameterValue.Value, parameterValueType.Value, !IsInstanceParameter);
else
parameter = ConsoleAppHelper.GetParameterHelper().AddCustomParameter(parameterName.SchemaName, element, parameterValue.Value, parameterValueType.Value, !IsInstanceParameter);

ConsoleAppHelper.SetExchangeUpdated(exchangeTitle.Value, true);
if (parameter == null)
{
Console.WriteLine("Parameter is not added.\n");
}
else
{
var builtInParameter = parameterName.Value == null ? "Custom" : "Built-In";
Console.WriteLine("Parameter is added.\nThis is "+builtInParameter+" parameter"+"\nParameter value type is "+ parameterValueType.Value);
}

return Task.FromResult(true);
return base.Execute();
}
}
}
32 changes: 32 additions & 0 deletions src/ConsoleConnector/Commands/AddTypeParamCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.DataExchange.ConsoleApp.Commands.Options;
using Autodesk.DataExchange.ConsoleApp.Helper;
using Autodesk.DataExchange.ConsoleApp.Interfaces;
using Autodesk.DataExchange.DataModels;

namespace Autodesk.DataExchange.ConsoleApp.Commands
{
internal class AddTypeParamCommand: AddParamCommand
{
public AddTypeParamCommand(IConsoleAppHelper consoleAppHelper) : base(consoleAppHelper)
{
this.IsInstanceParameter = false;
this.Name = "AddTypeParameter";
Description = "Add type parameters to element.";
}

public AddTypeParamCommand(AddTypeParamCommand addTypeParamCommand) : base(addTypeParamCommand)
{
this.IsInstanceParameter = addTypeParamCommand.IsInstanceParameter;
}

public override Command Clone()
{
return new AddTypeParamCommand(this);
}
}
}
6 changes: 3 additions & 3 deletions src/ConsoleConnector/Commands/CreateBrepCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public override Task<bool> Execute()
return Task.FromResult(false);
}

var revitExchangeData = ElementDataModel.Create(ConsoleAppHelper.GetClient(), exchangeData);
var brep = ConsoleAppHelper.GetGeometryHelper().CreateBrep(revitExchangeData);
ConsoleAppHelper.AddExchangeData(exchangeTitle.Value, revitExchangeData.ExchangeData);
var elementDataModel = ElementDataModel.Create(ConsoleAppHelper.GetClient(), exchangeData);
var brep = ConsoleAppHelper.GetGeometryHelper().CreateBrep(elementDataModel);
ConsoleAppHelper.AddExchangeData(exchangeTitle.Value, elementDataModel.ExchangeData);
Console.WriteLine("Element Id: " + brep.Id);
Console.WriteLine("Element Name: " + brep.Name);
Console.WriteLine("Category: " + brep.Category);
Expand Down
79 changes: 0 additions & 79 deletions src/ConsoleConnector/Commands/CreateCustomParameter.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/ConsoleConnector/Commands/CreateExchangeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public override async Task<bool> Execute()

var exchangeTitle = this.GetOption<ExchangeTitle>();
ExchangeDetails = await ConsoleAppHelper.CreateExchange(exchangeTitle.Value);
var revitExchangeData = ElementDataModel.Create(ConsoleAppHelper.GetClient());
ConsoleAppHelper.AddExchangeData(exchangeTitle.Value, revitExchangeData.ExchangeData);
var elementDataModel = ElementDataModel.Create(ConsoleAppHelper.GetClient());
ConsoleAppHelper.AddExchangeData(exchangeTitle.Value, elementDataModel.ExchangeData);
ConsoleAppHelper.AddExchangeDetails(exchangeTitle.Value, ExchangeDetails);
Console.WriteLine(exchangeTitle.Value + " exchange created!!!");
Console.WriteLine("ExchangeId: " + ExchangeDetails.ExchangeID);
Expand Down
6 changes: 3 additions & 3 deletions src/ConsoleConnector/Commands/CreateIfcCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public override Task<bool> Execute()
return Task.FromResult(false);
}

var revitExchangeData = ElementDataModel.Create(ConsoleAppHelper.GetClient(), exchangeData);
var ifc = ConsoleAppHelper.GetGeometryHelper().CreateIfc(revitExchangeData);
ConsoleAppHelper.AddExchangeData(exchangeTitle.Value,revitExchangeData.ExchangeData);
var elementDataModel = ElementDataModel.Create(ConsoleAppHelper.GetClient(), exchangeData);
var ifc = ConsoleAppHelper.GetGeometryHelper().CreateIfc(elementDataModel);
ConsoleAppHelper.AddExchangeData(exchangeTitle.Value,elementDataModel.ExchangeData);
ConsoleAppHelper.SetExchangeUpdated(exchangeTitle.Value, true);
Console.WriteLine("Element Id: " + ifc.Id);
Console.WriteLine("Element Name: " + ifc.Name);
Expand Down
75 changes: 0 additions & 75 deletions src/ConsoleConnector/Commands/CreateInstanceParameterCommand.cs

This file was deleted.

6 changes: 3 additions & 3 deletions src/ConsoleConnector/Commands/CreateMeshCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public override Task<bool> Execute()
return Task.FromResult(false);
}

var revitExchangeData = ElementDataModel.Create(ConsoleAppHelper.GetClient(), exchangeData);
var mesh = ConsoleAppHelper.GetGeometryHelper().CreateMesh(revitExchangeData);
ConsoleAppHelper.AddExchangeData(exchangeTitle.Value, revitExchangeData.ExchangeData);
var elementDataModel = ElementDataModel.Create(ConsoleAppHelper.GetClient(), exchangeData);
var mesh = ConsoleAppHelper.GetGeometryHelper().CreateMesh(elementDataModel);
ConsoleAppHelper.AddExchangeData(exchangeTitle.Value, elementDataModel.ExchangeData);
ConsoleAppHelper.SetExchangeUpdated(exchangeTitle.Value, true);
Console.WriteLine("Element Id: " + mesh.Id);
Console.WriteLine("Element Name: " + mesh.Name);
Expand Down
10 changes: 5 additions & 5 deletions src/ConsoleConnector/Commands/CreatePrimitiveGeometryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@ public override Task<bool> Execute()
return Task.FromResult(false);
}

var revitExchangeData = ElementDataModel.Create(ConsoleAppHelper.GetClient(), exchangeData);
var elementDataModel = ElementDataModel.Create(ConsoleAppHelper.GetClient(), exchangeData);

Element element;
if (primitiveGeometryOption.Value == PrimitiveGeometryType.Circle)
{
element = ConsoleAppHelper.GetGeometryHelper().AddCircle(revitExchangeData);
element = ConsoleAppHelper.GetGeometryHelper().AddCircle(elementDataModel);
}
else if (primitiveGeometryOption.Value == PrimitiveGeometryType.Line)
{
element = ConsoleAppHelper.GetGeometryHelper().AddLine(revitExchangeData);
element = ConsoleAppHelper.GetGeometryHelper().AddLine(elementDataModel);
}
else if (primitiveGeometryOption.Value == PrimitiveGeometryType.Point)
{
element = ConsoleAppHelper.GetGeometryHelper().AddPoint(revitExchangeData);
element = ConsoleAppHelper.GetGeometryHelper().AddPoint(elementDataModel);
}
else if (primitiveGeometryOption.Value == PrimitiveGeometryType.Polyline)
{
element = ConsoleAppHelper.GetGeometryHelper().AddPolyline(revitExchangeData);
}
else
{
element = ConsoleAppHelper.GetGeometryHelper().AddPrimitive(revitExchangeData);
element = ConsoleAppHelper.GetGeometryHelper().AddPrimitive(elementDataModel);
}

Console.WriteLine("Element Id: " + element.Id);
Expand Down
Loading

0 comments on commit 168173a

Please sign in to comment.