Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add image to drafting journal

Status
Not open for further replies.

ciach

Mechanical
Sep 23, 2011
19
Hi guys,
I'm looking for NX Api function to add image into drafting sheet. Any idea?
 
Replies continue below

Recommended for you

While in Drafting with a Drawing sheet displayed, go to...

Insert -> Image...

...where you will be able to insert either a .jpg, .png or .tif formatted image file onto the face of the drawing. Once placed, you will be able to drag it to the desired location, rotate at 90° increments, resize the image or change it's aspect ratio (after toggling OFF the aspect ratio lock icon) using the handles shown when editing the image. Note that this image is static and will NOT update if the original image file is edited.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
Is there a NX Open function to do this? I want to make this proces automatic with journal (VB)
 
I suspect not. It uses an older set of user interface tools which are not supported via journaling. Now there still might be an explicit NX Open call but doing a quick search of the NX Open functions I couldn't find anything that looks like it would address this.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
Edit this to suit your needs.

Code:
[COLOR=green]'eng-tips thread561-335144[/color]
[COLOR=green]'import image to drafting sheet[/color]

[COLOR=blue]Option Strict Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] NXOpen  
[COLOR=blue]Imports[/color] NXOpen.UF  

[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] ufs [COLOR=blue]As[/color] UFSession [COLOR=blue]=[/color] UFSession.GetUFSession  
        [COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work  

        [COLOR=blue]Dim[/color] imageFile [COLOR=blue]As String =[/color] "C:\temp\test.jpg"  
        [COLOR=blue]Dim[/color] sheetTag [COLOR=blue]As[/color] Tag [COLOR=blue]=[/color] Tag.Null  
        [COLOR=blue]Dim[/color] imageCoordinates(2) [COLOR=blue]As Double[/color]  
        imageCoordinates(0) [COLOR=blue]=[/color] 0  
        imageCoordinates(1) [COLOR=blue]=[/color] 0  
        imageCoordinates(2) [COLOR=blue]=[/color] 0  
        [COLOR=blue]Dim[/color] imageTag [COLOR=blue]As[/color] Tag [COLOR=blue]=[/color] Tag.Null  
        ufs.Drf.CreateImageFromFile(imageFile, sheetTag, imageCoordinates, imageTag)  

        [COLOR=blue]If[/color] imageTag.Equals(Tag.Null) [COLOR=blue]Then[/color]  
 [COLOR=green]'image was not imported[/color]
        End [COLOR=blue]If[/color]  

    End [COLOR=blue]Sub[/color]  


    [COLOR=blue]Public Function[/color] GetUnloadOption(ByVal dummy [COLOR=blue]As String[/color]) [COLOR=blue]As 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
 
It works, great man ! After test I will post my script at nxjournaling.com
 
It works perfectly, but...
When it inserts image, journal changes the size (or scale) of the picture. In format A4 it's ok, but in A3, A2 it's 2 times bigger. (Or mayby in A4 is 2 times smaller)
I am also wonder if its possible to define image size and image name during inserting image into drafting (with image name i would have chance to check if image is jet in drafting)
ufs.Drf.imageData? ufs.Drf.askImageData?
I'm using NX 8.0.3.4.
 
I'm unable to duplicate the scaling issue. I've added some code that reports the image dimensions, then scales the image to be 1/2 of the original width.

I've been looking at the initialize image data function in the help file, but I don't see an obvious way to associate that to the image that is being imported. I'll look into it more as I get time.

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

[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] ufs [COLOR=blue]As[/color] UFSession [COLOR=blue]=[/color] UFSession.GetUFSession  
        [COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work  
        [COLOR=blue]Dim[/color] lw [COLOR=blue]As[/color] ListingWindow [COLOR=blue]=[/color] theSession.ListingWindow  
        lw.Open()  

        [COLOR=blue]Dim[/color] imageFile [COLOR=blue]As String =[/color] "C:\temp\test.jpg"  
        [COLOR=blue]Dim[/color] sheetTag [COLOR=blue]As[/color] Tag [COLOR=blue]=[/color] Tag.Null  
        [COLOR=blue]Dim[/color] imageCoordinates(2) [COLOR=blue]As Double[/color]  
        imageCoordinates(0) [COLOR=blue]=[/color] 0  
        imageCoordinates(1) [COLOR=blue]=[/color] 0  
        imageCoordinates(2) [COLOR=blue]=[/color] 0  
        [COLOR=blue]Dim[/color] imageTag [COLOR=blue]As[/color] Tag [COLOR=blue]=[/color] Tag.Null  

        [COLOR=blue]Dim[/color] myImageData [COLOR=blue]As[/color] UFDrf.ImageData  

        ufs.Drf.CreateImageFromFile(imageFile, sheetTag, imageCoordinates, imageTag)  

        [COLOR=blue]If[/color] imageTag.Equals(Tag.Null) [COLOR=blue]Then[/color]  
 [COLOR=green]'image was not imported[/color]
        [COLOR=blue]Else[/color]  
            ufs.Drf.AskImageData(imageTag, myImageData)  
            lw.WriteLine("initial settings")  
            lw.WriteLine("original image height: " [COLOR=blue]&[/color] myImageData.height.ToString)  
            lw.WriteLine("original image width: " [COLOR=blue]&[/color] myImageData.width.ToString)  
            lw.WriteLine("aspect ratio locked: " [COLOR=blue]&[/color] myImageData.aspect_ratio_locked.ToString)  
            lw.WriteLine("name: " [COLOR=blue]&[/color] myImageData.image_name)  
            lw.WriteLine("")  
 [COLOR=green]'lock the aspect ratio[/color]
            ufs.Drf.SetImageAspectRatioLock(imageTag, [COLOR=blue]True[/color])  
 [COLOR=green]'resize width to be 1/2 original width[/color]
            ufs.Drf.SetImageWidth(imageTag, myImageData.width [COLOR=blue]/[/color] 2)  
        End [COLOR=blue]If[/color]  

        lw.Close()  

    End [COLOR=blue]Sub[/color]  


    [COLOR=blue]Public Function[/color] GetUnloadOption(ByVal dummy [COLOR=blue]As String[/color]) [COLOR=blue]As 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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor