Has anyone worked with setting the InSession.Views property?
The problem I have is that when I set the following property immediately after opening a document it doesn't work (i.e. the Views size is still 0 even though the viewSet has 4 items).
revitDocument.PrintManager.ViewSheetSetting.InSession.Views = viewSet;
but after modifying the In-Session view/sheet set using print dialog in revit, then I can assign to it.
does anyone know why?
Revit stores the current view sheet set in the variable Document.PrintManager.ViewSheetSetting.CurrentViewSheetSet and that's what it's really using . At the beginning when you are setting the InSession you should be setting the CurrentViewSheetSet instead. The reason that it is working after using the print dialog is that it is setting the CurrentViewSheetSet to InSession. What I would do is to create a temporary ViewSheetSetting on document open and then delete it when the document closes. Below is some of the code that I used though with mine I only kept the ViewSheetSetting for the scope of a single function call instead of from document open to document close.
For Open
const string tempoarySheetSetSettingName = "Temp Sheet Set";
ViewSheetSetting viewSheetSetting = _printManager.ViewSheetSetting;
//Save your temporary sheet set
_printManager.ViewSheetSetting.SaveAs(tempoarySheetSetSettingName);
ViewSheetSet selected = null;
FilteredElementCollector viewCollector = new FilteredElementCollector(document);
viewCollector.OfClass(typeof(ViewSheetSet));
//Find the sheet set that you just created
foreach (ViewSheetSet set in viewCollector.ToElements())
{
if (String.Compare(set.Name, tempoarySheetSetSettingName) == 0)
{
selected = set;
break;
}
}
//Set the current view sheet set to the one that you just created
viewSheetSetting.CurrentViewSheetSet = selected;
//Set the views to which ever set you would like to print
viewSheetSetting.CurrentViewSheetSet.Views = viewSetToPrint;
viewSheetSetting.Save();
For Printing
Your user will need to select the temporary view set that you created whenever they print.
For Close
_printManager.ViewSheetSetting.Delete();
In Revit 2015 using VB.Net I couldn't force this ViewSheetSet Colletor to work like this:
Dim VSSCollector As New FilteredElementCollector(curDoc)
VSSCollector.OfClass(oftype(ViewSheetSet))
Instead I used this and it worked:
Dim VSSCollector As New FilteredElementCollector(curDoc)
VSSCollector.OfClass(GetType(ViewSheetSet))
Related
I have a Visio stencil document with some shapes and I want to add a shape contained inside it to my document. Based on this example I was able to do it, the only issue is how to get rid of the dock panel which appears when opening stencil using Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked flag.
So after import I close the opened stencil document but the dock panel stays. Maybe I could close it programmatically too, but then I should consider complicated logic with tracking wheater this was opened or not to keep UI unchanged if the user opened this panel previously etc.
My question is there another option to import a shape from a stencil or a workaround for this panel and stencil document opening options (for instance to open stencil document hidden for user and close it afterwards silently)
// Microsoft.Office.Interop.Visio.Application Application
var documents = Application.Documents;
var document = documents.Add("");
var page = Application.ActivePage;
var visioStencil = documents.OpenEx(
#"c:\Users\user\Desktop\stencil.vssx",
(short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked);
var masters = visioStencil.Masters;
for (var i = 1; i <= masters.Count; ++i)
{
var item = masters.get_ItemU(i);
var name = item.Name;
if (name == "Master.2")
{
page.Drop(item, 10, 10);
break;
}
}
visioStencil.Close();
You can open the stencil document in a 'hidden' state and also use the Masters.Drop method to add directly to the target masters collection like this:
var targetDoc = vApp.Documents.Add("");
var sourceDoc = vApp.Documents.OpenEx(
#"c:\Users\user\Desktop\stencil.vssx",
(short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visAddHidden);
var sourceMasters = sourceDoc.Masters;
for (var i = 1; i <= sourceMasters.Count; ++i)
{
var sourceMaster = sourceMasters[i];
if (sourceMaster.Name == "Master.2")
{
targetDoc.Masters.Drop(sourceMaster, 10, 10);
break;
}
}
sourceDoc.Close();
Note that the if the target document already contains a master of the same name Visio will create a new master and append a number on the end. Also, bear in mind that Name and NameU may be different so you might want to match on the latter instead.
No need to loop through all the shapes in the stencil. You can access the shape by name:
targetDoc.Masters.Drop(sourceMasters["Master.2"], 10, 10);
I want to print all selected files which are displayed in a Datagrid.
I donĀ“t want to print them one after another, I want all to add them into a print queue because I want to use FinePrint.
FinePrint is a printer driver that can add all documents in the print queue to a single file for printing. In Windows Explorer you can select files and right-click Print on them. When FinePrint is selected as the default printer it opens the FinePrint Window and attaches all the selected Files to one file. Then you can do other stuff like set stamps on the pages.
I want to create the same thing in my WPF project, but it would be enough to just select files and click on a button.
EDIT:
The complete Method:
void btnPrint_Click(object sender, RoutedEventArgs e)
{
List<ZeichnungInDB> selectedItemsList = dataOutOfDb.SelectedItems.Cast<ZeichnungInDB>().ToList();
if(selectedItemsList.Count > 0)
{
PrintDialog printDialog = new PrintDialog();
FileInfo fileInfo;
if (printDialog.ShowDialog() == true)
{
foreach (ZeichnungInDB zeichnung in selectedItemsList)
{
fileInfo = new FileInfo(#"..." + zeichnung.Zeichnungsnummer + "_" + zeichnung.Index + "_VIN_" + zeichnung.Volante_Index + zeichnung.Extension);
using (FileStream file = fileInfo.OpenRead())
{
System.Windows.Markup.ParserContext context = new System.Windows.Markup.ParserContext();
context.BaseUri = new Uri(fileInfo.FullName, UriKind.Absolute);
object doc = (System.Windows.Markup.XamlReader.Load(file, context));
DocumentPaginator paginator = ((IDocumentPaginatorSource)doc).DocumentPaginator;
printDialog.PrintDocument(paginator, "Printing from MMS");
}
}
}
}
}
It throws a XamlParseException where I create the doc object, directly at the beginning of the File.
Basically you set a registry key (counter) and then print them the normal way (one after another) FinePrint decrements the counter and adds them to one job.
From: http://fineprint.com/fpsupport-topic/fineprint-developer-kit/
Using the CollectJobs registry setting, FinePrint will collect
multiple print jobs before printing them.
The DWORD registry key is:
HKEY_CURRENT_USER/Software/FinePrint
Software/FinePrint8/FinePrinters/FinePrint/CollectJobs
Set the CollectJobs value to the number of print jobs you want to
combine. Each time FinePrint receives a print job, it decrements the
counter. The counter value should be checked to ensure that it has
been decremented before the next job is sent. When all the jobs have
been collected and sent to the output device, the counter is set to
zero.
I grabbed the value from database and I am trying to assign those values in Edit Form. But the only problem is with the FileUpload. It don't take the value. Can anyone suggest me what I'm missing here
private void EditForDataByID(int TitleId)
{
ReadmoreController objFormController = new ReadmoreController();
ReadMoreInfo objInfo = objFormController.GetListObjectOfAllArticle(TitleId);
if (objInfo != null)
{
TextTitle.Text = objInfo.Title;
txtSummary.Text = objInfo.Summary;
TextDate.Text = objInfo.Date.ToString();
//FileUpload1.FileName=objInfo.Image; I even tried this but it doesn't work
FileUpload1 = objInfo.Image;
Session["TitleId"] = TitleId;
ListDiv.Visible = false;
form.Visible = true;
BindGrid();
}
}
For client security reason you can not assign value to FileUploadControl as it could cause the uploading of unwanted files from client machine. So let the use pick the file to upload.
If it is allowed then one can steel the important files from client machine like c:\PersonalPasswords
Edit Based on comments
If you need to ensure that user has selected an Image and does not need to change it then you can use a image control and assign image to it. Use the same image control to find if the image is selected or not.
I'm looking for the source code to collapse every methods of my active document using the VS2010 Addin.
For the moment I parse the text content of the document trying to match if the line is a method signature. If it is the case, I collapse the method.
TextSelection selection = (TextSelection)_applicationObject.ActiveDocument.Selection;
var editPoint = selection.ActivePoint.CreateEditPoint();
editPoint.MoveToLineAndOffset(1, 1);
while (!editPoint.AtEndOfDocument)
{
editPoint.StartOfLine();
var line = editPoint.GetText(editPoint.LineLength).TrimStart();
if (line.StartsWith("public"))
{
selection.MoveToLineAndOffset(editPoint.Line, 1);
_applicationObject.ExecuteCommand("Edit.ToggleOutliningExpansion");
}
// go to the next line
}
Does anyone could tell me if I'm on the good way or if there is an easiest way ?
Maybe I asked not so well my question. My real goal was to collapse all the code : properties, methods, comments with ///, using; but not the regions.
Here is one solution :
// reduce everything like Ctrl+M+O
_applicationObject.ExecuteCommand("Edit.CollapsetoDefinitions");
// save the cursor position
TextSelection selection = (TextSelection)_applicationObject.ActiveDocument.Selection;
var selectedLine = selection.ActivePoint.Line;
var selectedColumn = selection.ActivePoint.DisplayColumn;
// open the regions
selection.StartOfDocument();
while (selection.FindText("#region", (int)vsFindOptions.vsFindOptionsMatchInHiddenText))
{
// do nothing since FindText automatically expands any found #region
}
// put back the cursor at its original position
selection.MoveToDisplayColumn(selectedLine, selectedColumn);
I hope this could help
I created a new Excel file with C#.
When I open the document all the worksheets are align right to left.
How can I align the worksheet/workbook/window to display left to right grammatically?
Sub leftToRight()
Application.DefaultSheetDirection = xlLTR
ActiveSheet.DisplayRightToLeft = False
End Sub
You can also change the setting through Tools->Options->International. Note that you need to set/unset the Checkbox "View current sheet right-to-left" to change currently open sheets.
Edit: Sorry I accidentally interpreted your question as VBA.
Here is a c# Solution:
Excel.Application xlApp = new Excel.Application();
xlApp.Visible = true;
xlApp.Workbooks.Add(System.Type.Missing);
Excel.Worksheet active = (Excel.Worksheet)xlApp.ActiveSheet;
xlApp.DefaultSheetDirection = (int)Excel.Constants.xlLTR; //or xlRTL
active.DisplayRightToLeft = false;
I would like to introduce my implementation of this feature after i used marg concept and changed it to the right syntax for me:
public void SetWorksheetDirection(Application excel, bool isRTL)
{
Worksheet active = (Worksheet)excel.ActiveSheet;
if (isRTL)
excel.DefaultSheetDirection = (int)XlDirection.xlToRight;
else
excel.DefaultSheetDirection = (int)XlDirection.xlToLeft;
active.DisplayRightToLeft = isRTL;
}
Do this one time to change the default direction:
Alt+F11 to open the VBA editor
Ctrl+G to open the Immediate window
in the Immediate window type Application.DefaultSheetDirection = xlLTR and press Enter
Alt+Q to close the VBA editor
create a new workbook to test it
If you just wanted to organize some of the columns, you could use a line like this:
oWS.Range["A1:B2000"].HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlLeft;