Group Views based on Stock number

Group Views based on Stock number

floccipier
Advocate Advocate
1,081 Views
13 Replies
Message 1 of 14

Group Views based on Stock number

floccipier
Advocate
Advocate

Hi all, 

I am trying to arrange views so that similar stock numbers are in one group, while I can read the stock, add that to list and sort that I am bit clueless to use this information ot actually move and group views, any help regarding this would be highly appreciated. 

best regards, 
Sam

0 Likes
Accepted solutions (2)
1,082 Views
13 Replies
Replies (13)
Message 2 of 14

A.Acheson
Mentor
Mentor

Hi Sam,

Are you talking about moving drawing views here or something else? Can you share the rule you are using and some images of your desired workflow. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 14

floccipier
Advocate
Advocate

@A.Acheson wrote:

Hi Sam,

Are you talking about moving drawing views here or something else? Can you share the rule you are using and some images of your desired workflow. 


Hi Acheson, 

Thanks for your reply, and yes I am talking about drawing views.

so below is the code which reads all the stock number of part used in view and adds it to lits and later part of the code displays sorted list. 

 

Dim oApp = ThisApplication
Dim oDrawDoc As DrawingDocument
oDrawDoc = oApp.ActiveDocument
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet
Dim oList As New List(Of String)
Dim oSN As String

For Each oView As DrawingView In oSheet.DrawingViews

oSN = (oView.ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item _
("Design Tracking Properties").Item("Stock Number").Value)
oList.Add(oSN)
oList.Sort

Next


For Each str As String In oList
	 MessageBox.Show(Str)

Next

What I am trying to achieve is to arrange same stock number (part) views on drawings in one group (in one row may be) e.g.  all views with parts having "10 mm Plate" should be one group, "16 mm Plate" another group and son on. 
Let me know please if i need to provide more info. 

0 Likes
Message 4 of 14

floccipier
Advocate
Advocate

@JelteDeJong sorry to tag you but if you have bit of time to have a look at this please. 

0 Likes
Message 5 of 14

WCrihfield
Mentor
Mentor

Just to clarify the details of this task a bit more.  How many views are we talking about here on one sheet?  How do you want them grouped (each group is 1 vertical line of views ; each group is 1 horizontal line of views ; each group is rectangular with x number of columns and x number of rows ; other ; don't care)?  On the subject of knowing how to know which stock numbers to group together, do you mean that there may be multiple view which are using the same stock number, then only group views of that same stock number together, or are there stock numbers that are somehow similar to each other that you want grouped together?  If they are just similar, then how do we know which ones to group together?  How much space do you want between these views & groups of views?  What sheet size and orientation are you using?  Is there a Border & TitleBlock that we need to avoid when placing these views on the sheet?  Where is the TitleBlock on the sheet, and does it span the full width of the sheet, or just partial?

When doing it manually, with all of it in front of us is one thing, but trying to do this completely on a code screen, having never seen the drawing or the views to reference is quite another.

 

Some screen captured images of examples might help here, because as they say, "A picture is worth a thousand words."

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 14

floccipier
Advocate
Advocate

@WCrihfield Thanks for the reply. 


@WCrihfield wrote:

Just to clarify the details of this task a bit more.  How many views are we talking about here on one sheet? sometimes more than hundred. How do you want them grouped (each group is 1 vertical line of views ; each group is 1 horizontal line of views ; each group is rectangular with x number of columns and x number of rows ; other ; don't care)?  Each group in 1 hozrizontal Line. On the subject of knowing how to know which stock numbers to group together, do you mean that there may be multiple view which are using the same stock number, then only group views of that same stock number together, or are there stock numbers that are somehow similar to each other that you want grouped together? I have section (e.g. 100x50PFC) or Plate thickness (e.g. 6mm No Fold) description in stock number. So the code should group views of same stock number.  If they are just similar, then how do we know which ones to group together?  they have either same stock number or not, there is nothing as similar. How much space do you want between these views & groups of views?  What sheet size and orientation are you using?  Is there a Border & TitleBlock that we need to avoid when placing these views on the sheet?  Where is the TitleBlock on the sheet, and does it span the full width of the sheet, or just partial? We don't want veiws to overlap each other (5mm gap between two adjacent views). Considering some items are really small, In no case the gap between two views should be less than 10mm.  There are is no border and block restriction, views can be arranged and grouped anywhere needed. to make it simple lets assume that there is no title block. 

code can group it whereever needed (even outside of sheet if that's easy) and then designer would arrange the views however like or even copy and place them to additional sheets. 

When doing it manually, with all of it in front of us is one thing, but trying to do this completely on a code screen, having never seen the drawing or the views to reference is quite another.

 

Some screen captured images of examples might help here, because as they say, "A picture is worth a thousand words."


I can't post anything there, but if you have an email I can send you the a screen grab. 

Best regards, 
Flo

0 Likes
Message 7 of 14

JelteDeJong
Mentor
Mentor
Accepted solution

Is this what you are looking for?

Sub Main()
    Dim doc As DrawingDocument = ThisDoc.Document
    Dim sheet As Sheet = doc.ActiveSheet

    Dim viewDic As Dictionary(Of DrawingView, String) = New Dictionary(Of DrawingView, String)()
    For Each view As DrawingView In sheet.DrawingViews
        viewDic.Add(View, GetStockNumber(View))
    Next

    Dim viewDicOrderd = viewDic.OrderBy(Function(item) item.Value)

    Dim curentX As Double = 0
    Dim curentY As Double = 0
    Dim previousStockNumber As String = viewDicOrderd.First.Value
    Dim nextY As Double = 0
    For Each item In viewDicOrderd
        Dim view = item.Key
        Dim stockNumber = item.Value

        If (view.Parent IsNot sheet) Then
            view.CopyTo(sheet)
        End If

        If (stockNumber <> previousStockNumber) Then
            curentX = 0
            curentY = curentY + nextY + 0.5
        End If

        MoveView(item.Key, curentX, curentY)
        curentX = curentX + view.Width + 0.5
        nextY = Math.Max(nextY, view.Height)
        previousStockNumber = stockNumber
    Next
End Sub

Public Sub MoveView(view As DrawingView, X As Double, Y As Double)
    Dim oTg As TransientGeometry = ThisApplication.TransientGeometry
    X = X + view.Width / 2
    Y = Y + view.Height / 2

    Dim pos As Point2d = oTg.CreatePoint2d(X, Y)
    view.Position = pos
End Sub


Public Function GetStockNumber(view As DrawingView)
    Try
        Dim doc As Document = view.ReferencedDocumentDescriptor.ReferencedDocument
        Dim propSet As PropertySet = doc.PropertySets.Item("Design Tracking Properties")
        Dim prop As [Property] = propSet.Item("Stock Number")
        Return prop.Value
    Catch ex As Exception
        Return ""
    End Try
End Function

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 8 of 14

floccipier
Advocate
Advocate
Thank you so much, exactly what I needed.
Every time you provide solution it not only solves my problem it always teaches me more ways to doing things. Please accept gift of coffee which is not substitute of your time and effort, its merely way of saying thanks to you.
good night.
Message 9 of 14

JelteDeJong
Mentor
Mentor

Thank you for the coffee and have a good night!

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 10 of 14

floccipier
Advocate
Advocate

Hi @JelteDeJong
your solution is delivering exactly what I requested for in OP but I have realised now that for each "Stock No" there are so many parts. Is it possible that it places views of every stock No on to a new sheet (renaming sheet name to Stock No). Sorry I should have thought about it in the beginning. 

0 Likes
Message 11 of 14

floccipier
Advocate
Advocate

@JelteDeJong I tried updating to put group of same stock number views on separate sheet - it creates the sheets ( I counted it creates as many as types of stock numbers and adds just one view on each sheet) but doesn't not successfully moves all the views. Can you please help me modify this, would be huge favour. Thank you.

 

 


@floccipier wrote:

Hi @JelteDeJong
your solution is delivering exactly what I requested for in OP but I have realised now that for each "Stock No" there are so many parts. Is it possible that it places views of every stock No on to a new sheet (renaming sheet name to Stock No). Sorry I should have thought about it in the beginning. 


 

0 Likes
Message 12 of 14

JelteDeJong
Mentor
Mentor
Accepted solution

you can try this:

Sub Main()
    Dim doc As DrawingDocument = ThisDoc.Document
    Dim sheet As Sheet = doc.ActiveSheet

    Dim viewDic As Dictionary(Of DrawingView, String) = New Dictionary(Of DrawingView, String)()
    For Each view As DrawingView In sheet.DrawingViews
        viewDic.Add(View, GetStockNumber(View))
    Next

    Dim viewDicOrderd = viewDic.OrderBy(Function(item) item.Value)

    Dim curentX As Double = 0
    Dim curentY As Double = 0
    Dim previousStockNumber As String = viewDicOrderd.First.Value
    Dim nextY As Double = 0
    Dim newSheet As sheet = doc.Sheets.Add()
    newSheet.Name = previousStockNumber
    For Each item In viewDicOrderd
        Dim view = item.Key
        Dim stockNumber = item.Value

        If (stockNumber <> previousStockNumber) Then
            curentX = 0
            curentY = 0 ' curentY + nextY + 0.5
            newSheet = doc.Sheets.Add()
            newSheet.Name = stockNumber
        End If

        view = view.CopyTo(newSheet)
        MoveView(view, curentX, curentY)
        curentX = curentX + view.Width + 0.5
        nextY = Math.Max(nextY, view.Height)
        previousStockNumber = stockNumber
    Next

    ' uncomment this next line if you want to delete the first sheet.
    ' sheet.Delete()
End Sub

Public Sub MoveView(view As DrawingView, X As Double, Y As Double)
    Dim oTg As TransientGeometry = ThisApplication.TransientGeometry
    X = X + view.Width / 2
    Y = Y + view.Height / 2

    Dim pos As Point2d = oTg.CreatePoint2d(X, Y)
    view.Position = pos
End Sub


Public Function GetStockNumber(view As DrawingView)
    Try
        Dim doc As Document = view.ReferencedDocumentDescriptor.ReferencedDocument
        Dim propSet As PropertySet = doc.PropertySets.Item("Design Tracking Properties")
        Dim prop As [Property] = propSet.Item("Stock Number")
        Return prop.Value
    Catch ex As Exception
        Return ""
    End Try
End Function

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 13 of 14

floccipier
Advocate
Advocate
Thank you so much.
0 Likes
Message 14 of 14

floccipier
Advocate
Advocate
i have sent you one email, commeting this to make sure that it doesn't go unattended or to spam.
0 Likes