Showing posts with label add on. Show all posts
Showing posts with label add on. Show all posts

Saturday, March 9, 2013

Revit Python Script Code Example - automatic rename view number in a sheet

hi, I rewrote the code in python script for revit 2012/2013, see how it works in video



the code is below, copy and save the code in a file named "sortSheetViews.py" or whatever. then follow the video to add this script to revit ribbon

import clr
import math
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import *
from Autodesk.Revit.DB.Analysis import *
from Autodesk.Revit.UI.Selection import *
from Autodesk.Revit.UI import *

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
#selection = list(__revit__.ActiveUIDocument.Selection.Elements)
uidoc = __revit__.ActiveUIDocument
#selection = __revit__.ActiveUIDocument.Selection.Elements
selelementsid=[]
#############################method###################################
#get views in a list
def viewSelectInList():
    sel = uidoc.Selection
    sel.Elements.Clear()
    loopSwitch = 1
    while loopSwitch==1:

        pickedOne = sel.PickObject(ObjectType.Element,"Pick view one by one, pick title block to finish")
        if pickedOne!= None :
            #revit 2013 use the statement below
            e = doc.GetElement(pickedOne.ElementId)
            #revit 2012 use the statement below
            #e = doc.GetElement(pickedOne)
#            TaskDialog.Show("Revit", e.Category.Name)
            if e.Category.Name.Equals("Title Blocks"):
#                TaskDialog.Show("Revit", e.Category.Name)
                loopSwitch = 0
            else:
                selelementsid.append(e.Id)
#                TaskDialog.Show("Revit", e.Category.Name)
        else:
            break
def reNumber (startInt):
    currentNo = startInt
    for eId in selelementsid:
        setViewPortNumber(eId,currentNo)
        currentNo += 1
def getViewByDetailNumber (vs,i):
    for v in vs.Views:
        if v.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).AsString() != None:
            if i == int(v.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).AsString()):
                return v
       
def setViewPortNumber (id, number):
    vs = doc.ActiveView
    stringOldNumber=doc.get_Element(id).get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).AsString()
#    print "viewport detail number: ",stringOldNumber
    if int(stringOldNumber) != number:
        if getViewByDetailNumber(vs, number) != None:
            #*****************to be finished here *****************
            getViewByDetailNumber(vs, number).get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).Set("999")
            doc.get_Element(id).get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).Set(str(number))
            getViewByDetailNumber(vs, 999).get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).Set(stringOldNumber)
        else:
            doc.get_Element(id).get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).Set(str(number))
#define a transaction variable and describe the transaction
t = Transaction(doc,'Sort Views in Sheet')

#start a transaction in the Revit database
t.Start()

#************ ADD YOUR OWN CODES HERE.******************
x = int(raw_input ("number start from: "))
viewSelectInList()
reNumber ( x )


#print "finished"
   
#************** END OF YOUR MAJOR CODES HERE.*********************
#commit the transaction to the Revit database
t.Commit()

#close the script window
__window__.Close()

the above video teachs how to add such scripts to revit ribbon

Thursday, March 7, 2013

Revit 2012 macro renumber sheet view code - for free

this macro is only for revit 2012, I did another version for 2013 using revit python shell.
the video is showing how it works.
 
1. In this application.cs add
public void sheetViewNumberSort()
        {
            if (this.Application.Documents.Size > 0)
            {
                //Get application and document objects
                foreach (Document document in this.Application.Documents)
                {
                    if (document.ActiveView != null)
                    {
                        ClassSheetViewNumberSort pswn = new ClassSheetViewNumberSort(this.Application, this.ActiveUIDocument, this.ActiveUIDocument.Document);
                        pswn.run();
                    }
                }
            }
            else MessageBox.Show("no open document!");
        }
2. the other code can be download at

there are some leftover codes in the file. but won't affect working

Cheers

Tuesday, December 25, 2012

Print pdf with sheet number and revision - FREE Revit addin


This page is the manual for PRINT PDF WITH SHEET NUMBER AND REVISION Revit 2012 /2013 add-in. The add-in / plug-in can be download at:

64 bit revit 2012/2013
http://pan.baidu.com/share/link?shareid=172850&uk=1259096542
https://docs.google.com/file/d/0B2dWucciRgDPbGFRcWxCNENxUms/edit?usp=sharing
32 bit revit 2012/2013
http://pan.baidu.com/share/link?shareid=172852&uk=1259096542
installation: extract and copy files into:
    • In a non-user specific location
      • For Windows XP - C:\Documents and Settings\All Users\Application Data\Autodesk\Revit\Addins\2012\
      • For Vista/Windows 7 - C:\ProgramData\Autodesk\Revit\Addins\2012\
        -- OR --
    • In a user specific location
        • For Windows XP - C:\Documents and Settings\<user>\Application Data\Autodesk\Revit\Addins\2012\
        • For Vista/Windows 7 - C:\Users\<user>\AppData\Roaming\Autodesk\Revit\Addins\2012\
in windows 7 you may need to unblock the dll by right clicking and select security -> unblock

How to use.

1. click inject default parameters to add default sheet parameters
2. create a sheet schedule and customize your pdf names
3. create a sheetset to put the sheets for printing there
4. change pdf setting as you want
5. save the setting so you can load it later
6. click print
After changing any printer settings, you need to restart revit.
This addin \ plug-in is free. If you like it please donate by click the link below.


Sunday, December 16, 2012

HOW TO INSTALL / COPY REVIT APPLICATION MACRO

Revit application macro modules usually saved in:
C:\ProgramData\Autodesk\Revit\Macros\2012\Architecture\VstaMacros\AppHookup\

to install application macros, you just need to copy your application macro module folder under it. You can also duplicate macro modules from this folder and copy onto different machines. The only disadvantage is macro contains source code. if you don't want to share source code with others. try to build add on or plug-ins.