how to create beams by lines from dwg linked into revit

how to create beams by lines from dwg linked into revit

27925916
Advocate Advocate
6,586 Views
26 Replies
Message 1 of 27

how to create beams by lines from dwg linked into revit

27925916
Advocate
Advocate

I link the dwg by the tool of revit  below:

 

test2.png

and we can see it  below, and I wanna know how to use the API to create beams by the lines standing for beam in dwg?

what should I do ?  should I use the API to select lines representing beams first ? and what to do next ..

test1.png

test3.png

0 Likes
Accepted solutions (1)
6,587 Views
26 Replies
Replies (26)
Message 2 of 27

matthew_taylor
Advisor
Advisor

Hi @27925916,

 

If you haven't installed RevitLookup yet, do so now. It is an indispensable tool that will help you reach an understanding of how the Revit object model is put together.

If you select an import instance, then 'Addins > Revit Lookup > Snoop Current Selection', you will be able to access the geometry (GeometryElement) of the import instance. From there choose 'View = Document.ActiveView', then 'GeometryElement', then 'GetSymbolGeometry', then 'GeometryElement'. You should then have another dialog with a list of the elements within the import instance. You should be able to check the GraphicsStyleId of each line, and if the GraphicsStyle is the one you want, then use its properties to create your framing instance. (You can clone either clone the line, or use its endpoints.)

 

There is an example in the SDK called CreateBeamsColumnsBraces that may be useful (amongst others).


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 3 of 27

27925916
Advocate
Advocate

thanks,I will try it ,and come back this question if any problemSmiley Tongue

0 Likes
Message 4 of 27

27925916
Advocate
Advocate

I have try the example of CreateBeamsColumnsBraces,and it showed show.png

it means I should load the family  of beams? why do I use LoadFamily to load a beam family ,it seems no working

0 Likes
Message 5 of 27

matthew_taylor
Advisor
Advisor

@27925916,

There are many examples of how to load a family in the SDK.

First of all, just manually load a family, and use its hard coded elementId. Once you have the bones working, you can go back and do that.

 

Also, refer here for help on getting started:

https://forums.autodesk.com/t5/revit-api-forum/check-out-the-self-paced-guide-my-first-plug-in/m-p/3...

 

 


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 6 of 27

27925916
Advocate
Advocate

I have a question,it is a whole piece after linking dwg into revit, like below it is a image dwg linked into revit:

211.pngwhen I select,it becomes like below:222.png

I can't select a single line ,there is any API to break down it into many lines so that I could select any line ?

there is such API to make it true?

 

 

and I have another question ,how to pick these text like below by API?    thanks very much,I am looking forward to your help

text.png

0 Likes
Message 7 of 27

matthew_taylor
Advisor
Advisor

Hi @27925916,

To select a single sub-object, you can use:

Dim ref As DB.Reference = _
   docUi.Selection.PickObject(UI.Selection.ObjectType.PointOnElement, "Pick element")
Dim elem As DB.Element = doc.GetElement(ref)
Dim geomObject As DB.GeometryObject = _
   elem.GetGeometryObjectFromReference(ref)
                 

Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 8 of 27

27925916
Advocate
Advocate

I have used the same way to pick,like below:

code.png

 

I mean when I pick , I want to  pick the single line like picture 1,not a whole dwg like picture 2:2221.png

                                                                                                      Picture 1

 

222.png

                                                                                                            picture 2

 

 

 

is there any API to breakdown the whole thing like picture2,so that I can use pickobject to select any line in it like pickture 1?

0 Likes
Message 9 of 27

matthew_taylor
Advisor
Advisor

Your geoObj object is the line (or text etc).

It's not an element, so you can't 'select' it, or highlight it, but the code I gave you allows you to retrieve the line and its properties.

If you want to simulate selection, you may be able to do that by creating detail or model lines over top of the geometry.


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 10 of 27

27925916
Advocate
Advocate

how to create detail or model lines over top of the geometry,?   retrieve all lines and text and create detail or model lines over them?

 

  I find revit has a function: when I select the whole block of dwg linked into revit, a button appears  like picture1:

C2.png

PICTURE 1

 

and when I click it, the dwg block breakdowns ,and it is no problem for me to pick any lines or text in this dwg block like below:

C3.png

I am confused how it realizes? is it also useing the way creating detail or model lines over top of the geometry?

but if I click Esc , it becomes back again, which is a whole dwg block again.

that is to say ,this button can allow us to pick any lines or text in a whole dwg block. how it do..Smiley Embarassed

 

 

 

 

0 Likes
Message 11 of 27

27925916
Advocate
Advocate

this is my dwg file , I link it into revit..maybe it is helpful for my question

0 Likes
Message 12 of 27

matthew_taylor
Advisor
Advisor

I understand what you are trying to do. The Revit API doesn't support selection for non-element objects (as far as I know).

The visualisation is not the important part of your coding. (You would probably do better to turn them straight into beams anyway.)

Here's a proof of concept:

#Region "Imported Namespaces"

Imports System.Linq
Imports Autodesk.Revit
Imports Autodesk.Revit.Attributes

#End Region

<Transaction(TransactionMode.Manual)> _
<Regeneration(RegenerationOption.Manual)> _
<Journaling(JournalingMode.UsingCommandData)> _
Public Class AddBeam
    Implements UI.IExternalCommand
    Public Function Execute(ByVal commandData As UI.ExternalCommandData, _
                            ByRef message As String, ByVal elements As DB.ElementSet) _
                        As UI.Result Implements UI.IExternalCommand.Execute
        Dim app As ApplicationServices.Application = commandData.Application.Application
        Execute = UI.Result.Failed
        Dim doc As DB.Document = commandData.Application.ActiveUIDocument.Document
        Dim docUi As UI.UIDocument = commandData.Application.ActiveUIDocument
        Dim ref As DB.Reference = _
            docUi.Selection.PickObject(UI.Selection.ObjectType.PointOnElement, "Pick element")
        Dim elem As DB.Element = doc.GetElement(ref)
        Dim geomObject As DB.GeometryObject = _
           elem.GetGeometryObjectFromReference(ref)
        If TypeOf (geomObject) Is DB.Line Then
            Dim line As DB.Line = TryCast(geomObject, DB.Line)
            Dim familySymbol As DB.FamilySymbol = New DB.FilteredElementCollector(doc) _
                                                .OfCategory(DB.BuiltInCategory.OST_StructuralFraming) _
                                                .OfClass(GetType(DB.FamilySymbol)) _
                                                .Cast(Of DB.FamilySymbol) _
                                                .FirstOrDefault
            Using trans As New DB.Transaction(doc, "Add Beam")
                trans.Start()
                Dim curve As DB.Curve = line
                Dim familyInstance As DB.FamilyInstance = _
                    doc.Create.NewFamilyInstance(curve, familySymbol, _
                         doc.ActiveView.GenLevel, DB.Structure.StructuralType.Beam)
                trans.Commit()
                Return UI.Result.Succeeded
            End Using
        End If
        Return Execute
    End Function
End Class

You'll need a framing family in your model.

 


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 13 of 27

27925916
Advocate
Advocate

it is possible for me to pick after exploding after linked DWG file using the API?

 I need to realize function that allows user to pick lines or text in dwg linked into revit,

if it is impossible, does it have the API to have a operation to pick different Layers in dwg linked into revit?

thanks very muchSmiley Embarassed

0 Likes
Message 14 of 27

27925916
Advocate
Advocate

it is possible for me to pick after exploding after linked DWG file using the API? I need to realize function that allows user to pick lines or text in dwg linked into revit.     If it is impossible, does it have the API to have a operation to pick different Layers in dwg linked into revit?

thanks very muchSmiley Embarassed

0 Likes
Message 15 of 27

27925916
Advocate
Advocate

if I retrive all data from the importinstance of dwg, how could I get the data of number which describes the line?

0 Likes
Message 16 of 27

27925916
Advocate
Advocate

Smiley EmbarassedI am sorry for the trouble I have caused you ,it is the first time for me to operate dwg linked into revit by api,

 

I have another question about how to get the text in dwg linkd into revit, and  one more question is how to make sure its relationship with lines standing for beams?

 

33.png

 

 

\ know these lines standing for beams could be achieved by geometry like that: 

331.png

0 Likes
Message 17 of 27

matthew_taylor
Advisor
Advisor

Hi @27925916,

It's no problem.

 

It's not helpful starting new topics asking the same thing. It was the weekend - be patient. 🙂

 

This is how you get the 'layer' name of an importInstance line:

Dim ref As DB.Reference = _
  docUi.Selection.PickObject(UI.Selection.ObjectType.PointOnElement, _
  "Pick element")
Dim elem As DB.Element = doc.GetElement(ref)
Dim geomObject As DB.GeometryObject = _
                   elem.GetGeometryObjectFromReference(ref)
If TypeOf (geomObject) Is DB.Line Then
   Dim graphicsStyleElem As DB.Element = doc.GetElement(geomObject.GraphicsStyleId)
   Dim graphicsStyle As DB.GraphicsStyle = _
      TryCast(graphicsStyleElem, DB.GraphicsStyle)
   MsgBox(String.Format("Layer Name={0}", _     
      graphicsStyle.GraphicsStyleCategory.Name))
End If

Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 18 of 27

27925916
Advocate
Advocate

Smiley EmbarassedI am so confused that I make a new topic about the same question...

yes ,I have used the way you advise to get the name of  'layer' about a line, and alse I can use it to get the  'layer' of text like below :text.png

but the GraphicsStyleCategory.Name is not the content inside it , and is there any way to get the content of it and its position? 

because I want to judge the relationship of the lines standing for beam and the text whcih describes the size of beam

 

0 Likes
Message 19 of 27

matthew_taylor
Advisor
Advisor

Hi @27925916,

I understand it looks very daunting, but I promise it's not that complicated.

You really need to refer to my first comment. It tells you exactly how to get all of the lines/text etc using RevitLookup. With RevitLookup, you can browse the content of your importInstance. RevitLookup is an open sourced app - just look at it's code to see how it gets the information it does, and use that in your app. You can step through the code as you follow my steps.

If you have trouble with that, it's probably worth going back a step and up-skilling yourself until you feel more comfortable with it.

(Of course, if you find you want someone to write the app for you, you may find this post useful: http://thebuildingcoder.typepad.com/blog/2011/12/finding-a-development-partner.html)

 


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 20 of 27

27925916
Advocate
Advocate

thanks, I have tried to use revitloopup,but I can;t find any information about text ,I delete all layers except layer standing size by text:

note111.png

I use revit lookup to query and find nothing about text:

ttt.png

 

0 Likes