How to get Vector of Column

Hi ppl;
Do you know any other node that i couldget vector of column other than “ToColumnGeometry”. Because in my case this node getting wrong value.

This looks right based on what I am seeing; do you have a small sample data set and .dyn to test with?

Okay it will be shared tomorrow. Since I’m outta office at the moment. Thanks for quick response.:pray:

Hi. I’m arincakkin’s friend. I sent you data and .dyn file. I hope if you can help us find out the way to solve it. Everything is quite okay. Just only the last past remain: rotate column with angle.

I do not see any file posted. Please upload to the forum when you have it.

Here are the files.
test_2023_11_15.rvt (5.2 MB)
Create Column_Structure Wall_2023_11_15.dyn (184.9 KB)

1 Like

Hi,
here an solution with Python

import clr 
import sys 
import System 
# Add references 
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

# Add references to 'RevitNodes' and 'RevitServices' for Revit-specific functionality
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

def get_DatasColumns_from_CAD(importinstance, lst_layerName=[]):
    datas = []  # Initialize an empty list to store data
    # Define vectors for X-axis and Z-axis
    vect_X = DS.Vector.XAxis()
    vect_axis = DS.Vector.ZAxis()
    # Create an Options object for importing geometry
    opt = Options()
    # Get the geometry of the import instance
    geoSet = importinstance.get_Geometry(opt)
    # Iterate through the geometry set
    for geo in geoSet:
        if isinstance(geo, GeometryInstance):
            for g in geo.GetInstanceGeometry():
                if isinstance(g, DB.PolyLine):
                    # Get the graphics style and name of the current polyline
                    gStyle = doc.GetElement(g.GraphicsStyleId)
                    gstyleName = gStyle.GraphicsStyleCategory.Name
                    # Check if the layer name is in the specified list
                    if gstyleName in lst_layerName:
                        # Create a DesignScript polygon from the polyline
                        ds_polygon = DS.Polygon.ByPoints([p.ToPoint() for p in g.GetCoordinates()])
                        # Explode the polygon into a list of DesignScript curves
                        lst_ds_curves = ds_polygon.Explode()
                        # Find the longest curve in the list
                        longest_curve = sorted(lst_ds_curves, key=lambda x: x.Length)[-1]
                        # Create a DesignScript surface from the perimeter points of the polyline
                        ds_surface = DS.Surface.ByPerimeterPoints([p.ToPoint() for p in list(g.GetCoordinates())[:-1]])
                        # Calculate the center point of the surface
                        pt_ds_center = ds_surface.PointAtParameter(0.5, 0.5)
                        # Get the direction of the longest curve
                        vector_direction = longest_curve.Direction
                        # Determine the clockwise factor based on the cross product with the X-axis
                        factor_clockwise = 1 if vector_direction.Cross(vect_X).Z < 0 else -1
                        # Calculate the angle from the X-axis
                        angle_from_BasisX = vector_direction.AngleWithVector(vect_X) * factor_clockwise
                        
                        # Append the data to the list
                        datas.append({
                            "Layer": gstyleName,
                            "Geometry": ds_polygon,
                            "Center": pt_ds_center,
                            "Direction": vector_direction,
                            "Angle": angle_from_BasisX,
                            "longest_curve": longest_curve,
                        })
                        
    return datas

# Unwrap the import instance and layer name list from the Revit input
importinstance = UnwrapElement(IN[0])
lst_layerName = IN[1]

# Call the function and assign the result to the output variable
OUT = get_DatasColumns_from_CAD(importinstance, lst_layerName)

if you want only vectors :point_down:

7 Likes

Thank you so much @c.poupin

1 Like

I add 2 properties (as key)

WidthColumn and LengthColumn I think you will need it :wink:

import clr 
import sys 
import System 
# Add references 
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

# Add references to 'RevitNodes' and 'RevitServices' for Revit-specific functionality
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

def get_DatasColumns_from_CAD(importinstance, lst_layerName=[]):
    datas = []  # Initialize an empty list to store data
    # Define vectors for X-axis and Z-axis
    vect_X = DS.Vector.XAxis()
    vect_axis = DS.Vector.ZAxis()
    # Create an Options object for importing geometry
    opt = Options()
    # Get the geometry of the import instance
    geoSet = importinstance.get_Geometry(opt)
    # Iterate through the geometry set
    for geo in geoSet:
        if isinstance(geo, GeometryInstance):
            for g in geo.GetInstanceGeometry():
                if isinstance(g, DB.PolyLine):
                    # Get the graphics style and name of the current polyline
                    gStyle = doc.GetElement(g.GraphicsStyleId)
                    gstyleName = gStyle.GraphicsStyleCategory.Name
                    # Check if the layer name is in the specified list
                    if gstyleName in lst_layerName:
                        # Create a DesignScript polygon from the polyline
                        ds_polygon = DS.Polygon.ByPoints([p.ToPoint() for p in g.GetCoordinates()])
                        # Explode the polygon into a list of DesignScript curves
                        lst_ds_curves = [curve for curve in ds_polygon.Explode() if curve.Length > 0.001]
                        # sort curves by length
                        sort_curves = sorted(lst_ds_curves, key=lambda x: x.Length)
                        # Find the shortest and longest curve in the list
                        sortest_curve, longest_curve  = sort_curves[0], sort_curves[-1]
                        # Create a DesignScript surface from the perimeter points of the polyline
                        ds_surface = DS.Surface.ByPerimeterPoints([p.ToPoint() for p in list(g.GetCoordinates())[:3]])
                        # Calculate the center point of the surface
                        pt_ds_center = ds_surface.PointAtParameter(0.5, 0.5)
                        # Get the direction of the longest curve
                        vector_direction = longest_curve.Direction
                        # Determine the clockwise factor based on the cross product with the X-axis
                        factor_clockwise = 1 if vector_direction.Cross(vect_X).Z < 0 else -1
                        # Calculate the angle from the X-axis
                        angle_from_BasisX = vector_direction.AngleWithVector(vect_X) * factor_clockwise
                        
                        # Append the data to the list
                        datas.append({
                            "Layer": gstyleName,
                            "Geometry": ds_polygon,
                            "Center": pt_ds_center,
                            "Direction": vector_direction,
                            "Angle": angle_from_BasisX,
                            "WidthColumn" : sortest_curve.Length,
                            "LengthColumn" : longest_curve.Length,
                            "longest_curve": longest_curve,
                        })
                        
    return datas

# Unwrap the import instance and layer name list from the Revit input
importinstance = UnwrapElement(IN[0])
lst_layerName = IN[1]

# Call the function and assign the result to the output variable
OUT = get_DatasColumns_from_CAD(importinstance, lst_layerName)
4 Likes

A post was merged into an existing topic: How to get curves from a .dwg?