Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Draw line while picking line's points in Revit 2014

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
Anonymous
3995 Views, 13 Replies

Draw line while picking line's points in Revit 2014

Hello again,

 

I'm trying to figure out if there is a way to programmatically allow the user to draw a line in Revit 2014 or to call the model-line command (using the line option, not rectangle, circle, etc). I need that the user call my command, this command shows a form that have an option that is "Draw the path", if the user clicks that option the form should hide/close and the user should be able to draw a model line directly inside the project. When the user ends to draw the line the form should be re-shown and it should have a reference to the drawn line.

 

I've searched all the day for a solution but found nothing, I've also search how to lunch a standard Revit command (such as model line) but the only way seems to call the PostCommand that will add the command to the queue and thus the command will be lunched after my command terminates. I've searched also how to draw a line having only the start point and positioning the endpoint under the mouse but it seems that the MouseMove event is not available on a Revit document..

 

Really there is no way to ask the user to draw a line??

 

Thank you!

Tobia

13 REPLIES 13
Message 2 of 14
Joe.Ye
in reply to: Anonymous

 

Revit didn't expose the API to draw a line interactively ( like the Jig in AutoCAD). 

 

Hope this workaround helps:

Make a line based family. Actually it is a model line in that family.

You can try this method: UIDocument.PromptForFamilyInstancePlacement(); to place the family instance in Revit model after click the option button.

Note: this method can only run when there is no active transaction.  So you should not start any transaction before calling this method PromptForFamilyInstancePlacement.

 

This workaround can make your user to draw line interactively. 



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Message 3 of 14
Anonymous
in reply to: Joe.Ye

Thank you for your reply but unfortunately it seems that your solution doesn't fit my needs: actually I need to draw a complete path and not a simple line, thus, from the second line, I need to specify the starting point of the lines..

I mean: the first line can be done with your solution, after the first line I need to continue the path using the ending point of the first line as the start point of the second and so on. And this cannot be achieved using the PromptForPlacement method.

 

Thank you

Tobia

Message 4 of 14
Anonymous
in reply to: Anonymous

What I do is get the user to first draw the path using a specific line type that is used only for this purpose, they can then simply swipe over the area of the model that contains the path to select it (and anything else) before running my command. The command first filters out anything that is not a line with the specified type and then uses the remaining path lines for input.

 

You could then also temporarily isolate the lines in the view and get the user to select the line that begins the path. From there you can rectify the line segments so that they are all linked end-to-start in the same direction.

 

Alternatively for non-looped paths, you could check all input lines to find those that are only joined at one end, then choose the one that is not joined at its start point to use as the origin. If you need to also handle looped paths, choose the model line with lowest ElementId value to use as the start and use its direction to determine path sequence.

 

This method gives the user freedom to take thier time constructing the path using all available views, editing tools, planes, constraints, etc. Without you having to handle all the possibilities.

Message 5 of 14
Joe.Ye
in reply to: Anonymous

 

Hi Tobia,

 

When drawing the line family instance using the PromptForPlacement() method, there is a checkbox named Chain in the option bar. If you check this, then you can draw line without break. The next line's start is the previous line's end point.

As a workaround, this seems helps, though it is not perfect.

 

Hope this helps, 

 

 


______________________________________________________________

If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Message 6 of 14
Anonymous
in reply to: Joe.Ye

And can this check be set programmatically?

Message 7 of 14
Anonymous
in reply to: Joe.Ye

There is also another problem:

The PromptForFamilyInstancePlacement(familySymbol) will return after the first segment even if the chain checkbox is checked, so I will have only a segment and not a complete path.

Message 8 of 14
Joe.Ye
in reply to: Anonymous

 

As my test, PromptForFamilyInstancePlacement() reminds users to draw more than one segements continuously. 

with regard to set the "Chain" check in the option bar, there is no API to set that. You can write a document to let you end-users to check that maually.

 

I have a very short SharpDevelop code to show the usage of the PromptForFamilyInstancePlacement(). 

 

<code>

     public void createByPromptForPlacement()
        {
         Selection sel = this.ActiveUIDocument.Selection;
            Document doc = this.ActiveUIDocument.Document;
            
            Reference ref1 = sel.PickObject(ObjectType.Element,"please pick  a beam to get its type");
            
            FamilyInstance beam = doc.GetElement(ref1) as FamilyInstance;
            
            UIDocument uidoc = new UIDocument(doc);
            uidoc.PromptForFamilyInstancePlacement(beam.Symbol);
            
        }

<code>

 

 

 



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Message 9 of 14
Anonymous
in reply to: Joe.Ye

you could put the family placement code in a loop and collect each path segment untill they hit escape to cancel, then catch the Autodesk.Revit.Exceptions.OperationCanceledException where you can then display a dialog asking if they are finished drawing the path and want to continue, or have actually changed thier mind and want to cancel the operation.

Message 10 of 14
Anonymous
in reply to: Anonymous

In that way how can I say that the second segment will start from the end point of the first one? I don't think it is a way to go..

Message 11 of 14
Anonymous
in reply to: Anonymous

The first call could be for family placement and subsequent calls could be just picking a point, you then add the family instance using the end of last segment and new point.

Message 12 of 14
Anonymous
in reply to: Anonymous

Yes, but in this way I will lose the possibility to enter the length of the segment by typing it.

Message 13 of 14
Anonymous
in reply to: Joe.Ye

You were right, I was using a trick in order to limit the inserted entities to 1 instance. Now I've managed to solve my problem, thank you very much!

The only limit is that I cannot check that option programmatically (and this can be annoying to exmplain to my end users..)

 

Tobia

Message 14 of 14
Anonymous
in reply to: Anonymous

If anything has been changed in Revit 2016? 

 

I'm trying to implement this code, but I'm getting an error:

Object reference not set to an instance of an object.

 

Anyone can help me? I want to allow user to draw detail curve and get its ID.

 

Thanks.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community