Modifying custom properties.

Modifying custom properties.

Anonymous
Not applicable
420 Views
10 Replies
Message 1 of 11

Modifying custom properties.

Anonymous
Not applicable
I am using the code below to modify Custom User Properties and then print the drawing (with the updated properties). The problem is that the properties on the drawing are still blank when the drawing is printed. When I single-step through the code, the drawing is updated correctly and printed.

I've tried to use the 'sleep' command to slow the code down to let the drawing update, but that hasn't worked. I've tried putting 'DoEvents' calls in but that doesn't help either. I've used the App.Update method right before I print, but the properties still don't update before printing.

Does anyone have any other suggestions? It seems that the only way I can get the drawing to update is to step through the code, which must be giving Inventor enough processing time to update the drawing sheet.

tia

Public Sub ModifyISOBlockInfo(ByVal oDoc As DrawingDocument)
Dim oProperties As PropertySets
Dim oPropertySet As PropertySet
Dim oProperty As Inventor.Property

Set oProperties = oDoc.PropertySets

For Each oPropertySet In oProperties
If (oPropertySet.Name = "Inventor User Defined Properties") Then
For Each oProperty In oPropertySet
'Debug.Print oProperty.Name, oProperty.Value
Select Case LCase(oProperty.Name)
Case "epnumber"
'nothing yet

Case "jobinfo"
oProperty.Value = frmBatchPlot.txtJobDesc.Text

Case "jobquantity"
oProperty.Value = FileRS!qty

Case "pdesc"
oProperty.Value = Trim(FileRS!descr)

Case "pnumber"
oProperty.Value = Trim(FileRS!pnumber)

Case "timenuser"
oProperty.Value = Format(Now, "M/dd/yyyy hh:mm ampm")

End Select
DoEvents
Next oProperty
End If
Next
End Sub

Public Sub PrintInventorDrawing(ByRef oDrawDoc As DrawingDocument)
'Call UpdateStatusBox("Printing " & oDrawDoc.FullFileName)
frmBatchPlot.lblStatus3 = "Plotting"

Call ModifyISOBlockInfo(oDrawDoc)

' Set a reference to the print manager object of the active document.
' This will fail if a drawing document is not active.
Dim oPrintMgr As DrawingPrintManager
Set oPrintMgr = oDrawDoc.PrintManager

oPrintMgr.NumberOfCopies = frmBatchPlot.txtDrawingCopies

' Set the paper size.
oPrintMgr.PaperSize = kPaperSizeLetter

' Set to print all sheets.
oPrintMgr.PrintRange = kPrintAllSheets

DoEvents
Sleep (10000)
DoEvents
Call CheckFlexGridPosition("Plotted")


' Submit the print.
oPrintMgr.SubmitPrint

oDrawDoc.close
end sub
0 Likes
421 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
Just glancing at the code...did you try an oDoc.Update ? -- Sean Dotson, PE Autodesk Inventor Certified Expert http://www.sdotson.com Check the Inventor FAQ for most common questions www.sdotson.com/faq.html ----------------------------------------------------------------------- "clu82" wrote in message news:8153207.1078521964122.JavaMail.jive@jiveforum1.autodesk.com... > I am using the code below to modify Custom User Properties and then print the drawing (with the updated properties). The problem is that the properties on the drawing are still blank when the drawing is printed. When I single-step through the code, the drawing is updated correctly and printed. > > I've tried to use the 'sleep' command to slow the code down to let the drawing update, but that hasn't worked. I've tried putting 'DoEvents' calls in but that doesn't help either. I've used the App.Update method right before I print, but the properties still don't update before printing. > > Does anyone have any other suggestions? It seems that the only way I can get the drawing to update is to step through the code, which must be giving Inventor enough processing time to update the drawing sheet. > > tia > > Public Sub ModifyISOBlockInfo(ByVal oDoc As DrawingDocument) > Dim oProperties As PropertySets > Dim oPropertySet As PropertySet > Dim oProperty As Inventor.Property > > Set oProperties = oDoc.PropertySets > > For Each oPropertySet In oProperties > If (oPropertySet.Name = "Inventor User Defined Properties") Then > For Each oProperty In oPropertySet > 'Debug.Print oProperty.Name, oProperty.Value > Select Case LCase(oProperty.Name) > Case "epnumber" > 'nothing yet > > Case "jobinfo" > oProperty.Value = frmBatchPlot.txtJobDesc.Text > > Case "jobquantity" > oProperty.Value = FileRS!qty > > Case "pdesc" > oProperty.Value = Trim(FileRS!descr) > > Case "pnumber" > oProperty.Value = Trim(FileRS!pnumber) > > Case "timenuser" > oProperty.Value = Format(Now, "M/dd/yyyy hh:mm ampm") > > End Select > DoEvents > Next oProperty > End If > Next > End Sub > > Public Sub PrintInventorDrawing(ByRef oDrawDoc As DrawingDocument) > 'Call UpdateStatusBox("Printing " & oDrawDoc.FullFileName) > frmBatchPlot.lblStatus3 = "Plotting" > > Call ModifyISOBlockInfo(oDrawDoc) > > ' Set a reference to the print manager object of the active document. > ' This will fail if a drawing document is not active. > Dim oPrintMgr As DrawingPrintManager > Set oPrintMgr = oDrawDoc.PrintManager > > oPrintMgr.NumberOfCopies = frmBatchPlot.txtDrawingCopies > > ' Set the paper size. > oPrintMgr.PaperSize = kPaperSizeLetter > > ' Set to print all sheets. > oPrintMgr.PrintRange = kPrintAllSheets > > DoEvents > Sleep (10000) > DoEvents > Call CheckFlexGridPosition("Plotted") > > > ' Submit the print. > oPrintMgr.SubmitPrint > > oDrawDoc.close > end sub
0 Likes
Message 3 of 11

Anonymous
Not applicable
I had a similar problem with custom properties. I tried unsuccesfully to use an oDoc.Update My solution with the guidance of Charles Bliss was to write the following code Public Sub TitleBlockRefresh(sTBname As String) 'this function was written to refresh the title block after custom properties had 'been updated. ''''Dim sTBname As String ''''sTBname = "Sedgman" Dim oDoc As Document Set oDoc = ThisApplication.ActiveDocument Dim oTBlock As TitleBlockDefinition Set oTBlock = oDoc.TitleBlockDefinitions.Item(sTBname) 'Stop Dim oSketch As DrawingSketch Call oTBlock.Edit(oSketch) Call oTBlock.ExitEdit(True) End Sub Regards Martin Wright "clu82" wrote in message news:8153207.1078521964122.JavaMail.jive@jiveforum1.autodesk.com... > I am using the code below to modify Custom User Properties and then print the drawing (with the updated properties). The problem is that the properties on the drawing are still blank when the drawing is printed. When I single-step through the code, the drawing is updated correctly and printed. > > I've tried to use the 'sleep' command to slow the code down to let the drawing update, but that hasn't worked. I've tried putting 'DoEvents' calls in but that doesn't help either. I've used the App.Update method right before I print, but the properties still don't update before printing. > > Does anyone have any other suggestions? It seems that the only way I can get the drawing to update is to step through the code, which must be giving Inventor enough processing time to update the drawing sheet. > > tia > > Public Sub ModifyISOBlockInfo(ByVal oDoc As DrawingDocument) > Dim oProperties As PropertySets > Dim oPropertySet As PropertySet > Dim oProperty As Inventor.Property > > Set oProperties = oDoc.PropertySets > > For Each oPropertySet In oProperties > If (oPropertySet.Name = "Inventor User Defined Properties") Then > For Each oProperty In oPropertySet > 'Debug.Print oProperty.Name, oProperty.Value > Select Case LCase(oProperty.Name) > Case "epnumber" > 'nothing yet > > Case "jobinfo" > oProperty.Value = frmBatchPlot.txtJobDesc.Text > > Case "jobquantity" > oProperty.Value = FileRS!qty > > Case "pdesc" > oProperty.Value = Trim(FileRS!descr) > > Case "pnumber" > oProperty.Value = Trim(FileRS!pnumber) > > Case "timenuser" > oProperty.Value = Format(Now, "M/dd/yyyy hh:mm ampm") > > End Select > DoEvents > Next oProperty > End If > Next > End Sub > > Public Sub PrintInventorDrawing(ByRef oDrawDoc As DrawingDocument) > 'Call UpdateStatusBox("Printing " & oDrawDoc.FullFileName) > frmBatchPlot.lblStatus3 = "Plotting" > > Call ModifyISOBlockInfo(oDrawDoc) > > ' Set a reference to the print manager object of the active document. > ' This will fail if a drawing document is not active. > Dim oPrintMgr As DrawingPrintManager > Set oPrintMgr = oDrawDoc.PrintManager > > oPrintMgr.NumberOfCopies = frmBatchPlot.txtDrawingCopies > > ' Set the paper size. > oPrintMgr.PaperSize = kPaperSizeLetter > > ' Set to print all sheets. > oPrintMgr.PrintRange = kPrintAllSheets > > DoEvents > Sleep (10000) > DoEvents > Call CheckFlexGridPosition("Plotted") > > > ' Submit the print. > oPrintMgr.SubmitPrint > > oDrawDoc.close > end sub
0 Likes
Message 4 of 11

Anonymous
Not applicable
I spent quite a while investigating this and there is an issue with the title block updating when the properties are modified. Inventor triggers off the view being activated for it to update them. Here's some sample code that uses the SetFocus Windows API function to force this activation. If you insert this code into your VBA application project and then create a toolbar button for it, you should see the title block immediately update every time you press the button. ' Declare the SetFocus Windows API function. Public Declare Function SetFocus Lib "user32" (ByVal hwnd As Long) As Long Public Sub UpdatePropsAndTitleBlock() Dim oDoc As Document Set oDoc = ThisApplication.ActiveDocument ' Get the author property. Dim oAuthorProp As Property Set oAuthorProp = oDoc.PropertySets.Item("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}").ItemByPropI d(kAuthorSummaryInformation) ' Change the value of the property. This sets it to the current time ' so it's easy to see it change from one run to another. oAuthorProp.Value = Format(Now, "h:m:s") ' Call SetFocus to cause the title block to update. SetFocus ThisApplication.MainFrameHWND End Sub -- Brian Ekins Developer Technical Services, Autodesk Discussion Q&A: http://www.autodesk.com/discussion "clu82" wrote in message news:8153207.1078521964122.JavaMail.jive@jiveforum1.autodesk.com... > I am using the code below to modify Custom User Properties and then print the drawing (with the updated properties). The problem is that the properties on the drawing are still blank when the drawing is printed. When I single-step through the code, the drawing is updated correctly and printed. > > I've tried to use the 'sleep' command to slow the code down to let the drawing update, but that hasn't worked. I've tried putting 'DoEvents' calls in but that doesn't help either. I've used the App.Update method right before I print, but the properties still don't update before printing. > > Does anyone have any other suggestions? It seems that the only way I can get the drawing to update is to step through the code, which must be giving Inventor enough processing time to update the drawing sheet. > > tia > > Public Sub ModifyISOBlockInfo(ByVal oDoc As DrawingDocument) > Dim oProperties As PropertySets > Dim oPropertySet As PropertySet > Dim oProperty As Inventor.Property > > Set oProperties = oDoc.PropertySets > > For Each oPropertySet In oProperties > If (oPropertySet.Name = "Inventor User Defined Properties") Then > For Each oProperty In oPropertySet > 'Debug.Print oProperty.Name, oProperty.Value > Select Case LCase(oProperty.Name) > Case "epnumber" > 'nothing yet > > Case "jobinfo" > oProperty.Value = frmBatchPlot.txtJobDesc.Text > > Case "jobquantity" > oProperty.Value = FileRS!qty > > Case "pdesc" > oProperty.Value = Trim(FileRS!descr) > > Case "pnumber" > oProperty.Value = Trim(FileRS!pnumber) > > Case "timenuser" > oProperty.Value = Format(Now, "M/dd/yyyy hh:mm ampm") > > End Select > DoEvents > Next oProperty > End If > Next > End Sub > > Public Sub PrintInventorDrawing(ByRef oDrawDoc As DrawingDocument) > 'Call UpdateStatusBox("Printing " & oDrawDoc.FullFileName) > frmBatchPlot.lblStatus3 = "Plotting" > > Call ModifyISOBlockInfo(oDrawDoc) > > ' Set a reference to the print manager object of the active document. > ' This will fail if a drawing document is not active. > Dim oPrintMgr As DrawingPrintManager > Set oPrintMgr = oDrawDoc.PrintManager > > oPrintMgr.NumberOfCopies = frmBatchPlot.txtDrawingCopies > > ' Set the paper size. > oPrintMgr.PaperSize = kPaperSizeLetter > > ' Set to print all sheets. > oPrintMgr.PrintRange = kPrintAllSheets > > DoEvents > Sleep (10000) > DoEvents > Call CheckFlexGridPosition("Plotted") > > > ' Submit the print. > oPrintMgr.SubmitPrint > > oDrawDoc.close > end sub
0 Likes
Message 5 of 11

Anonymous
Not applicable
Sean: Yes I tried the 'Update' method of all of the relevant objects, but none worked.

Martin: With minor modifications, that code worked. Thank you (and Charles).

'change the parameters to the new values, then call this code
Dim oActiveDoc As Inventor.Document
Set oActiveDoc = oInvApp.ActiveDocument
Dim oSketchDef As SketchedSymbolDefinition
Set oSketchDef = oActiveDoc.SketchedSymbolDefinitions("ISO PLOT BLOCK")
Dim oSketch As DrawingSketch
Set oSketch = oSketchDef.Sketch
Call oSketchDef.Edit(oSketch)
Call oSketchDef.ExitEdit(True)
0 Likes
Message 6 of 11

Anonymous
Not applicable
Brian,
I am updating the Custom drawing properties objects so I thought the principle would be the same, so I replaced this code (which is a hack, but worked)

Dim oActiveDoc As Inventor.Document
Set oActiveDoc = oInvApp.ActiveDocument
Dim oSketchDef As SketchedSymbolDefinition
Set oSketchDef = oActiveDoc.SketchedSymbolDefinitions("ISO PLOT BLOCK")
Dim oSketch As DrawingSketch
Set oSketch = oSketchDef.Sketch
Call oSketchDef.Edit(oSketch)
Call oSketchDef.ExitEdit(True)

with your suggested code

SetFocus oInvApp.MainFrameHWND

but it didn't work for me. Neither did this:

SetFocus oDrawDoc.Views(1).hwnd

where oDrawDoc is dimensioned as a DrawingDocument.

Since your code is updating a "view", I thought I would try using the hWnd from the Drawing Document View, but that didn't work. So for now I'm back to the code shown previously.
0 Likes
Message 7 of 11

Anonymous
Not applicable
The sample I provided isn't actually doing a "view" update but is setting the focus to Inventor. The same thing would happen if you were to open another application and then switch the focus back to Inventor by clicking somewhere within a window. I don't remember the details now, but there was an issue specific to custom properties. However, in general this should work for standard and custom properties. I modified my sample to edit the value of a custom property instead and it worked correctly. It's a custom property in the drawing document called "CustomTest". The problems I have seen in the past were case specific and only happened with certain files. Public Sub UpdatePropsAndTitleBlock2() Dim oDoc As Document Set oDoc = ThisApplication.ActiveDocument ' Get the author property. Dim oCustomProp As Property Set oCustomProp = oDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}").Item("Custo mTest") ' Change the value of the property. This sets it to the current time ' so it's easy to see it change from one run to another. oCustomProp.Value = Format(Now, "h:m:s") SetFocus ThisApplication.MainFrameHWND End Sub -Brian "clu82" wrote in message news:3574437.1078768062413.JavaMail.jive@jiveforum1... > Brian, > I am updating the Custom drawing properties objects so I thought the principle would be the same, so I replaced this code (which is a hack, but worked) > > Dim oActiveDoc As Inventor.Document > Set oActiveDoc = oInvApp.ActiveDocument > Dim oSketchDef As SketchedSymbolDefinition > Set oSketchDef = oActiveDoc.SketchedSymbolDefinitions("ISO PLOT BLOCK") > Dim oSketch As DrawingSketch > Set oSketch = oSketchDef.Sketch > Call oSketchDef.Edit(oSketch) > Call oSketchDef.ExitEdit(True) > > with your suggested code > > SetFocus oInvApp.MainFrameHWND > > but it didn't work for me. Neither did this: > > SetFocus oDrawDoc.Views(1).hwnd > > where oDrawDoc is dimensioned as a DrawingDocument. > > Since your code is updating a "view", I thought I would try using the hWnd from the Drawing Document View, but that didn't work. So for now I'm back to the code shown previously.
0 Likes
Message 8 of 11

Anonymous
Not applicable
The code you are showing isn't printing though. The problem arises when I try to print right after setting the properties. I use your code AND right after that code, I do this:

oPrintMgr.SubmitPrint

The properties update on the screen, but the printout doesn't show them. I've tried putting a DoEvents call right after your code, but that doesn't help either.

The code that was listed several messages above (edit a sketch, then exit the edit) does work, but it seems like a major hack just to get the properties to print out.

Can you try to print the document after you do SetFocus to see if you get the same result that I get?

Thanks,
Jeff
0 Likes
Message 9 of 11

Anonymous
Not applicable
Hi Jeff, Trick with edit&exit sketch works for me from Inv6 when I first time discover it and announced to Autodesk. This is terrible shit solution which is slow & screen blinking. I do not understand why it is still on the list when ~2 years passes. Looks like one of the never solved problems. It comes over and over on this forum :) Regards, Adam "clu82" wrote in message news:27316797.1078783993159.JavaMail.jive@jiveforum1... > The code you are showing isn't printing though. The problem arises when I try to print right after setting the properties. I use your code AND right after that code, I do this: > > oPrintMgr.SubmitPrint > > The properties update on the screen, but the printout doesn't show them. I've tried putting a DoEvents call right after your code, but that doesn't help either. > > The code that was listed several messages above (edit a sketch, then exit the edit) does work, but it seems like a major hack just to get the properties to print out. > > Can you try to print the document after you do SetFocus to see if you get the same result that I get? > > Thanks, > Jeff
0 Likes
Message 10 of 11

Anonymous
Not applicable
Jeff, I tried printing and it's still working correctly for me. Below is the code I tested with. The first print had the original text of the custom property and the second print had the current time. As I mentioned before, there is another problem that will cause the title block to not update when custom properties are changed. This problem is case specific, but I don't know what causes a drawing to start having this problem. I suspect this is the problem you're having and the only solution I know of in this case is the one that's already been suggested. I agree with the others that this is not a very good solution and I also hope it is fixed soon. Public Sub UpdatePropsAndTitleBlock2() Dim oDoc As Document Set oDoc = ThisApplication.ActiveDocument oDoc.PrintManager.SubmitPrint ' Get the author property. Dim oCustomProp As Property Set oCustomProp = oDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}").Item("Custo mTest") ' Change the value of the property. This sets it to the current time ' so it's easy to see it change from one run to another. oCustomProp.Value = Format(Now, "h:m:s") SetFocus ThisApplication.MainFrameHWND oDoc.PrintManager.SubmitPrint End Sub -- Brian Ekins Developer Technical Services, Autodesk Discussion Q&A: http://www.autodesk.com/discussion "clu82" wrote in message news:27316797.1078783993159.JavaMail.jive@jiveforum1... > The code you are showing isn't printing though. The problem arises when I try to print right after setting the properties. I use your code AND right after that code, I do this: > > oPrintMgr.SubmitPrint > > The properties update on the screen, but the printout doesn't show them. I've tried putting a DoEvents call right after your code, but that doesn't help either. > > The code that was listed several messages above (edit a sketch, then exit the edit) does work, but it seems like a major hack just to get the properties to print out. > > Can you try to print the document after you do SetFocus to see if you get the same result that I get? > > Thanks, > Jeff
0 Likes
Message 11 of 11

Anonymous
Not applicable
Ok, Thank you Brian.
0 Likes