Quantcast
Channel: All Revit API Forum posts
Viewing all 66666 articles
Browse latest View live

Re: How to get Parameter named "W"


Re: Can't rotate element into this position

$
0
0

Dear Dirk,

 

I am anything but a content creation expert.

 

However, I can imagine that some people might solve this by adding parameters controlling rotation to the family definition itself.

 

For instance, you could add one to control rotation around the Z axis through the insertion point (0 to 360 degrees), and another to control the rotation "out of" the XY plane through the insertion point (0 to 90 degrees).

 

Would that not be simple to achieve, understand and control?

 

Might it possibly be a best practice?

 

Have you ensured that you are following best practices in your family definitions?

 

Please do, for your own good!

 

I hope this helps.

 

Cheers,

 

Jeremy

Re: Can't rotate element into this position

$
0
0

Hallo Jeremy,

 

thanks for the Suggestion, I agree this would be the best solution, and in fact similar to an Adaptive Element.

Unfortunatley I tried doing this, but could not figure out how to for example add a Parameter Controlling Rotation about ist own axis.

Could you pls Point me to a post where this would be described?

dirk

Re: Get selected elements from linked model

$
0
0

No response from the forum.Smiley Sad

 

I hope what I have asked is achievable.

 

Thanks & Regards

Sanjay Pandey

Re: Place a door tag at the center of the hosting door swing curve

$
0
0

The tag has a GetTaggedLocalElement() method that provides the door it's attached to.  I typed all of this directly in the browser so watch for typos.

 

 

using System;
using Autodesk.Revit.DB;

namespace DoorTags
{
    internal static class IndependentTagExtensions
    {
        public static bool IsAttachedToValidDoor(this IndependentTag tag)
        {
            var hostDoor = (FamilyInstance)tag.GetTaggedLocalElement();

if(hostDoor == null) {
return false;
}

var isValidDoor = hostDoor.IsValidDoor();
return isValidDoor; } public static void MoveToCenterOfDoorSwing(this IndependentTag tag) { //todo: Move the tag
//Here my crystal ball shows what may be a GetOptimalTagLocationPoint() method
//which is also in your new FamilyInstanceExtensions class... } }


internal static class FamilyInstanceExtensions
{
public static bool IsValidDoor(this FamilyInstance door)
{
//todo: test if your door name contains 'single'
//and any other tests that make this a valid door.
}
} }

 

Re: Schedule category

$
0
0

That was very  helpful. I was able to use viewschedule.Definition.CategoryId and compare it with doc.Settings.Categories to get the desired results

 

Document doc = this.Document;
			ViewSchedule mvs = doc.ActiveView as ViewSchedule;

			Category mcat = null;

			using (Transaction t = new Transaction(doc, "create Schedule"))
			{
				t.Start();
				{
					foreach (Category c in doc.Settings.Categories)
					{
						if (c.Name.ToLower() == "mechanical equipment")
						{
							mcat = c;
						}
					}
					//is the schedule for Mechanical equipment?
					if(mvs.Definition.CategoryId==mcat.Id)
					{
						//Schedule Definition
						ScheduleDefinition msd = mvs.Definition;
						//Add parameters to schedule
						ScheduleField mnamefield = msd.AddField(new SchedulableField(ScheduleFieldType.Instance, new ElementId(BuiltInParameter.ALL_MODEL_MARK)));

					}

Re: Schedule category

$
0
0

Or simply:

Public Shared Function GetBuiltinCategory(ByVal categoryId As DB.ElementId) _
     As DB.BuiltInCategory
  Return DirectCast( _
     [Enum].Parse(GetType(DB.BuiltInCategory), categoryId.IntegerValue), _
     DB.BuiltInCategory)
End Function

Volume of Profile in model

$
0
0

Hi,

 

Volume of Profile in model "0.049" but same value through .Net AsValueString comes "0.05" as volume. 

how to solve it.

attached snap for reference.

 

Thanks

-RK

 

 

 

 


Re: FamilyInstance fails to properly locate instance

$
0
0

The familyInstancenNeeds to be rotated about all 3 axes, and around ist center axis.

When I use plane-based Elements it Fails. Even when I use the template "M_Mechanische Geräte.rft", and uncheck the BuiltInParameter FAMILY_ALWAYS_VERTICAL, it fails. It seems that in Revit it is impossible to instantiate and then rotate an Element around the 3 axis of a coordinate System. There is always something illogical at Play.

Re: IMAGECLIP option simliar to AutoCAD in Revit

$
0
0

Dear Rajesh,

 

Thank you for your query.

 

As you are presumably aware, AutoCAD and Revit address extremely different audiences:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.41

 

Furthermore, in order to remain within the strict constraints required by the BIM, the Revit API hardly ever provides any functionality that is not supported first by the user interface.

 

Therefore, unless the features you are requesting are available through the user interface, they will hardly be available programmatically either.

 

In order to request new functionality, both for the UI and API, please submit your entry to the Revit Idea Station:

 

https://forums.autodesk.com/t5/revit-ideas/idb-p/302

 

Alternatively, I would suggest that you export the image yourself and then clip it using other Revit independent tools, e.g., implement the required clipping using AutoCAD, an open source image manipulation program like GIMP (https://en.wikipedia.org/wiki/GIMP) or using your own post-processing methods implemented externally.

 

I hope this helps.

 

Best regards,

 

Jeremy

Re: Volume of Profile in model

$
0
0

Avoid using AsValueString, unless you need exactly what it returns.

 

The other methods AsInteger, AsDouble, AsString, etc., return the real underlying database values.

 

AsValueString does not.

InstanceVoidCutUtils.AddInstanceVoidCut() is disabled to called from the Updater

$
0
0

Hello,

The InstanceVoidCutUtils.AddInstanceVoidCut() API method is disabled to be used inside of a Dinamic Model Updater (DMU). Updater throws an exception when you try to use this function. This is the message "This method may not be called during dynamic update."

 

I have attached a C# sample and a Revit file so that you could reproduce the problem. You need to move the void instance that is in the Revit project so that Updater could react, and you could reproduce the issue.

 

We need to use this function from the Updater because when users want to copy, paste and mirror the instances, they forgot to select the void cutters because they are not visible, and they are small. As a consequence, We need to create them again and do the cutting process by using the  InstanceVoidCutUtils.AddInstanceVoidCut().

 

We will be very grateful if you could enable this function in the Dynamic Model Updater for next Revit API version.

Also, if you could give us some directions to solve this issue, we will appreciate a lot.

 

Thank you in advance!

Marcelo

how to rotate a FamilyInstance around 3 axes

$
0
0

Can anyone please show me how to rotate a FamilyInstance derived from Metric Generic Model.rft about the 3 axes?

 

Re: Keynote creation within API - still not possible?

$
0
0

It seems you still can't create keynotes through the API in 2017. 

 

I have a project where I wanted to replace all the material tags with material keynotes.  I was thinking about this, and I did manage to find a workaround.  While it works with material keynotes it may not work with element keynotes.

 

Rather than trying to create a keynote, you could simply copy a single keynote around the model using the ElementTransformUtils.CopyElements method.  That method will allow you to copy a tag from one view to another. 

 

You can only copy keynotes when the reference planes are the same, so I created a keynote on a north/south section and east/west section.  That allowed me to paste one of those two keynotes to any other view.  If your building has any angled facades you may need more seed keynotes.

Re: Place a door tag at the center of the hosting door swing curve

$
0
0

 I appreciate the code and the time you are putting into this, as all the people on this forum thread. I still have questions ....

 

I'm not sure if you realize but there is a way to get the door tag from a list of doors but I am not sure if it is possible to get the host door from a list of tags. For me to get the tag id, I need to 'fake delete' the component and then call an exception shown in this example http://thebuildingcoder.typepad.com/blog/2009/06/host-reference.html 

 

unless you know of another way, I need to first collect all my doors, then get their associated tags and then test if the door is valid, then move the door tag. 

 

Hope that all makes sense. 

 

 


Re: Place a door tag at the center of the hosting door swing curve

$
0
0

Ok  I got somewhere today 

 

I implemented the first method 'Door Tags' successfully

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Reflection;

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace DoorTags
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class MoveDoorTags : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // get the active document in revit
            var activeDoc = commandData.Application.ActiveUIDocument.Document;
            var activeView = commandData.Application.ActiveUIDocument.ActiveGraphicalView;

            // create a new filtered collection of door tags and their ids
            var tagCollector = new FilteredElementCollector(activeDoc, activeView.Id);

            // Find the doors whos tags needs to be moved  ---'tagsToMove'
            var tagsToMove = tagCollector.
                OfCategory(BuiltInCategory.OST_DoorTags).
                OfClass(typeof(IndependentTag)).
                OfType<IndependentTag>().

                // calling an external method that will test if the door is a valid door type.
                Where(tag => tag.IsAttachedToValidDoor());

            // returns
            using (var tr = new Transaction(activeDoc, "Move Tags"))
            {
                foreach (var tag in tagsToMove)
                {
                    tag.MoveToCenterOfDoorSwing();
                }
            }
            return Result.Succeeded;
        }
    }
}

and the second ' IndependentTagExtension'

 

using System;
using Autodesk.Revit.DB;

namespace DoorTags
{
    internal static class IndependentTagExtensions
    {
        // check if the doortag is attached to a valid door
        public static bool IsAttachedToValidDoor(this IndependentTag tag)
        {
            // call the GetTaggedLocalElement method to get the host Door
            var hostDoor = (FamilyInstance)tag.GetTaggedLocalElement();
            if (hostDoor == null)
            {
                return false;
            }
            // if there is a door, call the IsValidDoor method to check if it is a valid door
            bool IsAttachedToValidDoor = hostDoor.IsValidDoor();

            return IsAttachedToValidDoor;
        }
        // move the tag to the right position
        public static void MoveToCenterOfDoorSwing(this IndependentTag tag)
        {
            // get the optimal tag location
            XYZ movePosition = hostDoor.GetOptimalTagLocation();
            if (movePosition != null)
            {
                LocationPoint tagLocation = tag.Location as LocationPoint;

                XYZ oldPlace = tagLocation.Point;

                // Move the tag to new location.
                XYZ newPlace = movePosition;
                ElementTransformUtils.MoveElement(document, column.Id, newPlace);
            }
        }
            public static void GetTaggedLocalElement(this familyInstance door)
        {
            var hostDoor = familyInstance.independentTag.GetTaggedLocalElement(); // Will this actually work?
            if (hostDoor != null)
            {
                var GetTaggedLocalElement = taggedLocalElement;
            }
            return GetTaggedLocalElement;
        }
    }
}
           

I am just having trouble with the last part of the final method 'FamilyInstanceExtension'

 

using System;
using System.Linq;
using Autodesk.Revit.DB;

namespace DoorTags
{
    internal static class FamilyInstanceExtensions
    {
        private static Options Option;

        public static bool IsValidDoor(this IndependentTag tag)
        {
            // String of valid doors, get hostDoor, get family name of HostDoor
            string searchString = "Single";
            // Get hostDoor id number
            var hostDoor = (FamilyInstance)tag.GetTaggedLocalElement();
            string FamilyName = hostDoor.Symbol.Family.Name; // get family name from the current hostDoor

            // Test if the doorHost family name contains "single", this will determine if it is valid or not
            if (FamilyName.Contains(searchString) != true)
            {
                return false;
            }
            bool IsValidDoor = true;
            return IsValidDoor;
        }

        public static void GetOptimalTagLocationPoint(this IndependentTag tag,
            Autodesk.Revit.DB.FamilyInstance Instance, Autodesk.Revit.ApplicationServices.Application app,
            Autodesk.Revit.DB.Element element, Options geoOptions, Arc arc)
        {
            // Get the hostDoor id from the tag
            var hostDoor = (FamilyInstance)tag.GetTaggedLocalElement();

            // get hostDoor geometry instance
            Autodesk.Revit.DB.GeometryElement geoElement = hostDoor.get_Geometry(geoOptions);

            // Get geometry object
            foreach (GeometryObject geoObject in geoElement)
            {
                // Get the geometry instance which contains the geometry information
                Autodesk.Revit.DB.GeometryInstance instance =
                       geoObject as Autodesk.Revit.DB.GeometryInstance;
                if (null != instance)
                {
                    GeometryElement instanceGeometryElement = instance.GetInstanceGeometry();
                    foreach (GeometryObject o in instanceGeometryElement)
                    {
                        // try to find door Curve in the set of instance geometry
                        Curve curve = o as Curve;
                        if (Curve != null)
                        {
                            XYZ curveCentre = instanceGeometryElement.curve.Center;
                            XYZ curveMidPoint = instanceGeometryElement.curve.Evaluate(0.5, true);
                            this.curveCentre = p1;
                            this.curveMidPoint = p2;
                            float frac = 0.5;

                            XYZ OptimalTagLocationPoint = (p1.X + frac * (p2.X - p1.X), p1.Y + frac * (p2.Y - p1.Y)));
                            return;
                        }
                        // write an exception error messgae "We couldnt move" + tag + "door tag."
                    }
                }
            }
            XYZ GetOptimalTagLocationPoint = OptimalTagLocation;
        }
    }
}

The section I am having trouble with is detecting the 'arc' information from my door instance geometry. This wouldn't be something you know how to fix? 

 

 

 

Re: difference between ElementTransformUtils.RotateElement and Location.Rotate

$
0
0

Dear Dirk,

 

 

 

As  notice I guess the basic difference between in term of work:

 fi.Location.rotate : Rotate element with their dependent element. Suppose B element attached with A if you use Location.Rotate(A) it rotate B also. While ElementTransfomUtil rotate only specified element.

You can also see their metadata summary.

Re: Can't rotate element into this position

$
0
0

Hello Jeremy,

 

you wrote:

 

"For instance, you could add one to control rotation around the Z axis through the insertion point (0 to 360 degrees), "

 

could you please point me to a post where this implementation is explained in detail?

dirk

Re: Can't rotate element into this position

$
0
0
Use Like This,

XYZ point1 = new XYZ(10, 20, 0);
XYZ point2 = new XYZ(10, 20, 30);
// The axis should be a bound line.
Line axis = document.Application.Create.NewLineBound(point1, point2);
ElementTransformUtils.RotateElement(document, element.Id, axis, Math.PI / 3.0)

Re: Can't rotate element into this position

Viewing all 66666 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>