Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

code snippet to set an arraylist containing the titleblocks on current sheet

Can someone help me with a VB code snippet - on a current sheet , I need to collect (all) titleblock(s) into an array,
and afterwards delete the titleblock(s).

maybee piece of this syntax can be used:
xxxxxxxxxxxxxxx ToArray(GetType(Annotations.TitleBlock ))?

 

Lars

6 REPLIES

Re: code snippet to set an arraylist containing the titleblocks on current sheet

There is the NXOpen.Update.AddToDeleteList() method, which doesn't need an array, so you can add objects one by one.

 

The TitleBlock property of the DraftingAnnotationManager returns the collection of title blocks, where each member can be checked with the GetViews() method, if the title block is contained on the displayed drawing.

 

Sorry have not needed this, so no example code.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community
Solution
Solution
Accepted by topic author LarsKlokmose
‎08-26-2015 04:32 AM

Re: code snippet to set an arraylist containing the titleblocks on current sheet

Try this:

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Annotations

Module collect_and_delete_titleblocks

    Dim theSession As Session = Session.GetSession()

    Sub Main()

        Dim dp As Part = theSession.Parts.Display

        Dim allTBs() As TitleBlock = dp.DraftingManager.TitleBlocks.ToArray()

        Dim theMarkId As Session.UndoMarkId = _
            theSession.SetUndoMark(Session.MarkVisibility.Visible, _
                                   "Delete Title BLocks")

        theSession.UpdateManager.AddToDeleteList(allTBs)
        theSession.UpdateManager.DoUpdate(theMarkId)

    End Sub

    Sub Echo(ByVal output As String)

        theSession.ListingWindow.Open()
        theSession.ListingWindow.WriteLine(output)
        theSession.LogFile.WriteLine(output)

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function

End Module

Solution
Solution
Accepted by topic author LarsKlokmose
‎08-26-2015 04:32 AM

Re: code snippet to set an arraylist containing the titleblocks on current sheet

Lars,

 

CAUTION - I just noticed you said "on a current sheet".  The example code I posted does not restrict itself to the current sheet - It finds all of the TitleBlock objects in the dislayed part and removes them.

 

Regards,

 

Steve

 

Re: code snippet to set an arraylist containing the titleblocks on current sheet

Hi Steve -

 

Thank you very much.

 

"DraftingManager"  -  I have missed this Class !!!

(I'm not used to programming within NXdrafting environmet.)

 

I have created a program that will replace our TitleBlocks on all sheets with a newer one, (added 2 cells) in a drawing part. Everything works fine.

But the way I deleted the TitleBlock until now, was simply delete all on layer 255.

But it was not a "clean" solution - and in few parts our TitleBlock's is not placed on layer 255!!

But now - deleting theTitleBlock itself - its a super solution.

It doesnt matter that all TitleBlocks are deleted in one call - but do you know if it can be asked

for the TitleBlock's sheet status ?

 

Again . Thank you .

 

Lars

 

 

Solution
Solution
Accepted by topic author LarsKlokmose
‎08-26-2015 04:32 AM

Re: code snippet to set an arraylist containing the titleblocks on current sheet

Search the GTAC solutions for "AskDrawingSheet", "nx_api4936", or "nx_api4937". It contains a function that will return the drawing sheet of a given object.

Solution
Solution
Accepted by topic author LarsKlokmose
‎08-26-2015 04:32 AM

Re: code snippet to set an arraylist containing the titleblocks on current sheet


LarsKlokmose wrote:
"DraftingManager"  -  I have missed this Class !!!

(I'm not used to programming within NXdrafting environmet.)



From the TitleBlock class, you can find the way back to the DraftingManager class by following the remarks at the bottom of the class description page in the NXOpen .NET API reference.

TitleBlock => DefineTitleBlockBuilder => CreateDefineTitleBlockBuilder => TitleBlockCollection => DraftingApplicationManager => Part.DraftingManager

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community