Change Schedule Filter value

Change Schedule Filter value

Anonymous
Not applicable
2,275 Views
3 Replies
Message 1 of 4

Change Schedule Filter value

Anonymous
Not applicable

Hi,

 

I am trying to use this code for duplicate a schedule view and change the filter value.

The code works, the schedule is duplicated, but the value is not changed. I also tried to commit the transaction and restart it before the filter, and regenerate document but not work.

what am I doing wrong?

 

 Dim lst_viewAbaco As List(Of View) = ED_Utility.FiltraAbaco(_doc, "ED-RDET_ABACO")

            'Dim viewAbacoID As ElementId = Nothing

            Dim viewAbaco As ViewSchedule = Nothing

            Dim t1 As New Transaction(_doc, "CopySchedule")

            Try
                t1.Start()

                For Each v As ViewSchedule In lst_viewAbaco

                    If v.Name.ToUpper = "ED-RDET_ABACO" Then

                        viewAbaco = TryCast(_doc.GetElement(v.Duplicate(ViewDuplicateOption.Duplicate)), ViewSchedule)

                        Dim lst_Abaco As List(Of View) = ED_Utility.FiltraAbaco(_doc, "Abaco Armature Partizione" & " - " & str_Part)

                        If lst_Abaco.Count = 0 Then

                            If viewAbaco IsNot Nothing Then viewAbaco.ViewName = "Abaco Armature Partizione" & " - " & str_Part
                        Else

                            If viewAbaco IsNot Nothing Then viewAbaco.ViewName = "Abaco Armature Partizione" & " - " & str_Part & "_1"

                        End If
                        _doc.Regenerate()


                        Dim filter As ScheduleFilter = viewAbaco.Definition.GetFilter(0)
                        
                        If filter.IsStringValue Then

                            filter.SetValue(str_Part)

                        End If

                    End If
                Next

                t1.Commit()
            Catch exception1 As Exception
                t1.RollBack()
                Return 0

            End Try
0 Likes
Accepted solutions (1)
2,276 Views
3 Replies
Replies (3)
Message 2 of 4

JimJia
Alumni
Alumni
Accepted solution

Dear scarta,

 

Please call "SetFilter" function after setvalue.

 

... 
Dim filter As ScheduleFilter = viewAbaco.Definition.GetFilter(0)
                        
                        If filter.IsStringValue Then

                            filter.SetValue(str_Part)
                            
                            viewAbaco.Definition.SetFilter(0,filter)

                        End If
...

 

It seems you need to replace the old filter, so that it can work.

 

Please have a try.


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
Message 3 of 4

Anonymous
Not applicable

Thanks!!!

now work correctly!!

 

Stefano

0 Likes
Message 4 of 4

FrankHolidaytoiling
Advocate
Advocate

Thanx for the solution also worked for me. 

0 Likes