# How to get Vector of Column

**URL:** <https://forum.dynamobim.com/t/how-to-get-vector-of-column/95548>\
**Category:** Packages\
**Tags:** revit, archi-lab, geometry, dynamo\
**Created:** [November 15, 2023, 3:54pm UTC](https://forum.dynamobim.com/t/how-to-get-vector-of-column/95548 "2023-11-15T15:54:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![arincakkin](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@arincakkin](https://forum.dynamobim.com/u/arincakkin)\
**Post date:** [November 15, 2023, 3:54pm UTC](https://forum.dynamobim.com/t/how-to-get-vector-of-column/95548/1 "2023-11-15T15:54:39Z")

</div>

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.

 ![Ekran görüntüsü 2023-11-15 185317](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/d/8dcdc7062cdec26b9efc3be085748eaa329623c2.jpeg)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [November 15, 2023, 4:08pm UTC](https://forum.dynamobim.com/t/how-to-get-vector-of-column/95548/2 "2023-11-15T16:08:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![arincakkin](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@arincakkin](https://forum.dynamobim.com/u/arincakkin)\
**Post date:** [November 15, 2023, 4:54pm UTC](https://forum.dynamobim.com/t/how-to-get-vector-of-column/95548/3 "2023-11-15T16:54:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nhalq](https://avatars.discourse-cdn.com/v4/letter/n/e95f7d/32.png) [@nhalq](https://forum.dynamobim.com/u/nhalq)\
**Post date:** [November 16, 2023, 12:17pm UTC](https://forum.dynamobim.com/t/how-to-get-vector-of-column/95548/4 "2023-11-16T12:17:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [November 16, 2023, 1:11pm UTC](https://forum.dynamobim.com/t/how-to-get-vector-of-column/95548/5 "2023-11-16T13:11:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![arincakkin](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@arincakkin](https://forum.dynamobim.com/u/arincakkin)\
**Post date:** [November 17, 2023, 4:43am UTC](https://forum.dynamobim.com/t/how-to-get-vector-of-column/95548/6 "2023-11-17T04:43:10Z")

</div>

Here are the files.  
[test\_2023\_11\_15.rvt](https://forum.dynamobim.com/uploads/short-url/vbqIh81FfKJersvYxsG4hsBpGeE.rvt) (5.2 MB)  
[Create Column\_Structure Wall\_2023\_11\_15.dyn](https://forum.dynamobim.com/uploads/short-url/g7rJRbzZkpT0XiEf8kUBJywJBqP.dyn) (184.9 KB)

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [November 17, 2023, 3:27pm UTC](https://forum.dynamobim.com/t/how-to-get-vector-of-column/95548/7 "2023-11-17T15:27:31Z")

</div>

Hi,  
here an solution with Python

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/c/dcf180bdedd2781f0dcfda590c80886837c1928d.png)

```auto
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 👇

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/f/5fa8d63dc7d7c2e6c2e00befe3d5cb859de367df.png)

---

<div class="post-metadata">

**Author:** ![arincakkin](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@arincakkin](https://forum.dynamobim.com/u/arincakkin)\
**Post date:** [November 17, 2023, 7:09pm UTC](https://forum.dynamobim.com/t/how-to-get-vector-of-column/95548/8 "2023-11-17T19:09:24Z")

</div>

Thank you so much @c.poupin

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [November 17, 2023, 8:27pm UTC](https://forum.dynamobim.com/t/how-to-get-vector-of-column/95548/9 "2023-11-17T20:27:22Z")

</div>

I add 2 properties (as key)

`WidthColumn` and `LengthColumn` I think you will need it 😉

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/b/8bd74a6eb937694649b2a92f7a474d59a70678fd.png)

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [November 27, 2023, 1:15pm UTC](https://forum.dynamobim.com/t/how-to-get-vector-of-column/95548/10 "2023-11-27T13:15:54Z")

</div>

A post was merged into an existing topic: [How to get curves from a .dwg?](https://forum.dynamobim.com/t/how-to-get-curves-from-a-dwg/95782/8)
