Hi, I’m trying to create c# code, which one add Pipe to Revit. It works, but I don’t understand why coordinates are changed during this process. It’s look like scale from point, but I’dont do it in the code.
// Grasshopper Script Instance
#region Usings
#r "C:\ProgramData\Autodesk\Revit\Addins\2023\RhinoInside.Revit\R8\RhinoInside.Revit.dll"
#r "C:\Program Files\Autodesk\Revit 2023\RevitAPI.dll"
#r "C:\Program Files\Autodesk\Revit 2023\RevitAPIUI.dll"
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using Rhino;
using Rhino.Geometry;
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
using RhinoInside.Revit;
using RhinoInside.Revit.UI;
using RhinoInside.Revit.Convert.Geometry;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
#endregion
public class Script_Instance : GH_ScriptInstance
{
// active Revit version
public static string REVIT_VERSION = Revit.ActiveUIApplication.Application.VersionNumber;
// access the active document object
private Autodesk.Revit.DB.Document doc = Revit.ActiveDBDocument;
#region Notes
/*
Members:
RhinoDoc RhinoDocument
GH_Document GrasshopperDocument
IGH_Component Component
int Iteration
Methods (Virtual & overridable):
Print(string text)
Print(string format, params object[] args)
Reflect(object obj)
Reflect(object obj, string method_name)
*/
#endregion
private void RunScript(
bool GO,
List<object> Line,
List<object> systemType,
List<object> pipeType,
object level,
ref object pipeOut)
{
if (GO)
{
var lineList = new List<Rhino.Geometry.Line>();
var systemTypeIdList = new List<Autodesk.Revit.DB.ElementId>();
var pypeTypeIdList = new List<Autodesk.Revit.DB.ElementId>();
var pypeList = new List<Autodesk.Revit.DB.Plumbing.Pipe>();
var RevitLevel = (Autodesk.Revit.DB.Level)level;
var RevitLevelId = RevitLevel.Id;
foreach (var item in systemType)
{
var Revititem = (Autodesk.Revit.DB.Element)item;
systemTypeIdList.Add(Revititem.Id);
}
foreach (var item in pipeType)
{
var Revititem = (Autodesk.Revit.DB.Element)item;
pypeTypeIdList.Add(Revititem.Id);
}
foreach (var item in Line)
{
lineList.Add((Rhino.Geometry.Line)item);
}
var sP = new List<Autodesk.Revit.DB.XYZ>();
var eP = new List<Autodesk.Revit.DB.XYZ>();
for (int i = 0; i < lineList.Count; i++)
{
sP.Add(new Autodesk.Revit.DB.XYZ(lineList[i].FromX, lineList[i].FromY, lineList[i].FromZ));
eP.Add(new Autodesk.Revit.DB.XYZ(lineList[i].ToX, lineList[i].ToY, lineList[i].ToZ));
}
// create and start the transaction
using (Transaction t = new Transaction(doc, "CreatePipe"))
{
t.Start();
for (int i = 0; i < systemTypeIdList.Count; i++)
{
var Pipe = Autodesk.Revit.DB.Plumbing.Pipe.Create(
doc,
systemTypeIdList[i],
pypeTypeIdList[i],
RevitLevelId,
sP[i],
eP[i]);
pypeList.Add(Pipe);
}
// commit the changes after all changes has been made
t.Commit();
}
pipeOut = pypeList;
}
}
}
In a picture you can see green - Revit elements after adding from GR, Red - input to node. Please, any ideas.
XmlToRevit_forum.gh (92.9 KB)