Example:
Public Function Obj_220113a(commandData As ExternalCommandData, ByRef message As String, elements As ElementSet) As Result
Dim app = commandData.Application
Dim uidoc = commandData.Application.ActiveUIDocument
Dim IntDoc = uidoc.Document
Dim Pts As New List(Of XYZ)
While True
Try
Pts.Add(uidoc.Selection.PickObject(Selection.ObjectType.PointOnElement, "Pick point (esc. to exit)").GlobalPoint)
Catch ex As Exception
Exit While
End Try
End While
If Pts.Count = 0 Then
Return Result.Cancelled
End If
Dim MinX As Double = Pts.Min(Function(k) k.X)
Dim MinY As Double = Pts.Min(Function(k) k.Y)
Dim MinZ As Double = Pts.Min(Function(k) k.Z)
Dim TPath As String = app.Application.FamilyTemplatePath & "\" & "Metric Generic Model Adaptive.rft"
Dim FDoc As Document = app.Application.NewFamilyDocument(TPath)
Using Tx As New Transaction(FDoc, "Curve")
If Tx.Start = TransactionStatus.Started Then
Dim RPArray As New ReferencePointArray
For i = 0 To Pts.Count - 1
Dim Orig As XYZ = Pts(i)
Dim NewPt As New XYZ(Orig.X - MinX, Orig.Y - MinY, Orig.Z - MinZ)
RPArray.Append(FDoc.FamilyCreate.NewReferencePoint(NewPt))
Next
FDoc.FamilyCreate.NewCurveByPoints(RPArray)
Tx.Commit()
End If
End Using
Dim F As Family = FDoc.LoadFamily(IntDoc)
Dim SybId As ElementId = F.GetFamilySymbolIds()(0)
Dim FS As FamilySymbol = IntDoc.GetElement(SybId)
Dim G As Guid = Guid.NewGuid
Using Tx As New Transaction(IntDoc, "Place")
If Tx.Start = TransactionStatus.Started Then
F.Name = "RPT" & G.ToString
FS.Name = "RPT_T" & G.ToString
FS.Activate()
IntDoc.Create.NewFamilyInstance(New XYZ(MinX, MinY, MinZ), FS, StructuralType.NonStructural)
Tx.Commit()
End If
End Using
FDoc.Close(False)
Return Result.Succeeded
End Function

