Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Cheking a model for an attached drawing using VB 1

Status
Not open for further replies.

eroe

Mechanical
Jul 29, 2009
37
0
0
US
Does anyone know a command that checks if a the current model has a drawing sheet? I have been looking for a couple days so far, but have not found any luck..

Thanks for the help!

Eric Roe
Electro-Mechanical Engineer
Airfloat LLC
 
Replies continue below

Recommended for you

Each part has a drawing sheet collection that you can inspect to see if there are drawing sheets and if so, how many.

Code:
[COLOR=blue]Option[/color] [COLOR=blue]Strict[/color] [COLOR=blue]Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] NXOpen  

[COLOR=blue]Module[/color] Module1  

    [COLOR=blue]Sub[/color] Main()  

        [COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()  
        [COLOR=blue]Dim[/color] workpart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work  
        [COLOR=blue]Dim[/color] dwgSheets() [COLOR=blue]As[/color] Drawings.DrawingSheet [COLOR=blue]=[/color] workpart.DrawingSheets.ToArray  
        [COLOR=blue]Dim[/color] lw [COLOR=blue]As[/color] ListingWindow [COLOR=blue]=[/color] theSession.ListingWindow  
        lw.Open()  

        [COLOR=blue]Dim[/color] i [COLOR=blue]As[/color] [COLOR=blue]Integer[/color] [COLOR=blue]=[/color] 0  
        [COLOR=blue]For[/color] [COLOR=blue]Each[/color] dwg [COLOR=blue]As[/color] Drawings.DrawingSheet [COLOR=blue]In[/color] dwgSheets  
            lw.WriteLine("Sheet name: " [COLOR=blue]&[/color] dwg.Name)  
            lw.WriteLine("Length: " [COLOR=blue]&[/color] dwg.Length)  
            lw.WriteLine("Height: " [COLOR=blue]&[/color] dwg.Height)  
            lw.WriteLine("")  
        [COLOR=blue]Next[/color]  
        lw.WriteLine("There are " [COLOR=blue]&[/color] dwgSheets.Length [COLOR=blue]&[/color] " sheet(s) [COLOR=blue]in[/color] the file")  
        lw.Close()  

    End [COLOR=blue]Sub[/color]  


    [COLOR=blue]Public[/color] [COLOR=blue]Function[/color] GetUnloadOption(ByVal dummy [COLOR=blue]As[/color] [COLOR=blue]String[/color]) [COLOR=blue]As[/color] [COLOR=blue]Integer[/color]  

 [COLOR=green]'Unloads the image when the NX session terminates[/color]
        GetUnloadOption [COLOR=blue]=[/color] NXOpen.Session.LibraryUnloadOption.AtTermination  

    End [COLOR=blue]Function[/color]  

End [COLOR=blue]Module[/color]


www.nxjournaling.com
 
I can think of a couple ways to do this, but my problem lies in finding the appropriate VB commands to execute (this is usually my problem when it comes to writing journal files in Vb).

I currently have a journal file that will set the drafting sheet to display, and then save the file in modeling. The only problem is that sometimes there is a file that does not have a drawing sheet attached, so it throws an error.

If there was a command to check if drawing sheets exist, then I could use it in an if statement.

Or if there is a command that returns the number of drawing sheets in the file, then I can use an if statement to check if the command returns 'zero'...

These are my thoughts, which boils down to knowing the right command.

I still do not quite understand how people find these commands? I have not found a very easy way to search for a certain command.. (other than posting a thread on here, which has always worked great). If it is something simple, I usually record a journal, then cut and past the commands from the "auto code" into a new program in order to manipulate it to do what I want it to.

Can someone share how they learn so many commands? Or is it something that just comes with time, and experience?

Thanks again, and sorry for the double post with multiple questions...

Eric Roe
Electro-Mechanical Engineer
Airfloat LLC
 
Status
Not open for further replies.
Back
Top