public virtual async Task <ImageInsightResponse> GetImageInsightsAsync( string query = "", int height = 0, int width = 0, int count = 0, int offset = 0, string languageCode = "", AspectOptions aspect = AspectOptions.All, ColorOptions color = ColorOptions.All, FreshnessOptions freshness = FreshnessOptions.All, ImageContentOptions imageContent = ImageContentOptions.All, ImageTypeOptions imageType = ImageTypeOptions.All, LicenseOptions license = LicenseOptions.All, SizeOptions size = SizeOptions.All, SafeSearchOptions safeSearch = SafeSearchOptions.Off, List <ModulesRequestedOptions> modulesRequested = null, float cab = 0f, float cal = 0f, float car = 0f, float cat = 0f, int ct = 0, string cc = "", string id = "", string imgUrl = "", string insightsToken = "") { var url = GetImageInsightUrl(query, height, width, count, offset, languageCode, aspect, color, freshness, imageContent, imageType, license, size, safeSearch, modulesRequested, cab, cal, car, cat, ct, cc, id, imgUrl, insightsToken); var response = await RepositoryClient.SendPostMultiPartAsync(ApiKeys.BingSearch, url, "{}"); return(JsonConvert.DeserializeObject <ImageInsightResponse>(response)); }
/// <summary> /// Collect the parameters and export /// </summary> /// <returns></returns> public override bool Import() { using (Transaction t = new Transaction(m_activeDoc)) { t.SetName("Import"); t.Start(); // Step 1: Create an ImageType //ImageTypeOptions specify the source of the image // If the source is a PDF file then ImageTypeOptions can be used to: // - Select a specific page from the PDF // - Select a Resolution (in dots-per-inch) at which to rasterize the PDF // For other image types the page number should be 1, and the resolution is only used to determine the size of the image ImageTypeOptions typeOptions = new ImageTypeOptions(m_importFileFullName); ImageType imageType = ImageType.Create(m_activeDoc, typeOptions); // Step 2: Create an ImageInstance, but only if the active view is able to contain images. View view = CommandData.Application.ActiveUIDocument.Document.ActiveView; if (ImageInstance.IsValidView(view)) { // ImagePlacementOptions ImagePlacementOptions placementOptions = new ImagePlacementOptions(); placementOptions.PlacementPoint = Autodesk.Revit.DB.BoxPlacement.TopLeft; placementOptions.Location = new XYZ(1, 1, 1); ImageInstance imageInstance = ImageInstance.Create(m_activeDoc, view, imageType.Id, placementOptions); } t.Commit(); } return(true); }
public virtual ImageInsightResponse GetImageInsights( string query = "", int height = 0, int width = 0, int count = 0, int offset = 0, string languageCode = "", AspectOptions aspect = AspectOptions.All, ColorOptions color = ColorOptions.All, FreshnessOptions freshness = FreshnessOptions.All, ImageContentOptions imageContent = ImageContentOptions.All, ImageTypeOptions imageType = ImageTypeOptions.All, LicenseOptions license = LicenseOptions.All, SizeOptions size = SizeOptions.All, SafeSearchOptions safeSearch = SafeSearchOptions.Off, List <ModulesRequestedOptions> modulesRequested = null, float cab = 0f, float cal = 0f, float car = 0f, float cat = 0f, int ct = 0, string cc = "", string id = "", string imgUrl = "", string insightsToken = "") { return(Task.Run(async() => await GetImageInsightsAsync(query, height, width, count, offset, languageCode, aspect, color, freshness, imageContent, imageType, license, size, safeSearch, modulesRequested, cab, cal, car, cat, ct, cc, id, imgUrl, insightsToken)).Result); }
public static void SearchAndApplyScetch(Dictionary <string, ScetchImage> imagesBase, Element rebar, ScetchTemplate st, string imagesPrefix) { Debug.WriteLine("Try to apply scetch for rebar id" + rebar.Id.IntegerValue.ToString()); Document doc = rebar.Document; string imageParamName = SupportSettings.imageParamName; ScetchImage si = new ScetchImage(rebar, st); ImageType imType2 = null; Debug.WriteLine("Key: " + si.ImageKey); if (imagesBase.ContainsKey(si.ImageKey)) //такая картинка уже ранее генерировалась и есть в проекте { Debug.WriteLine("Scetch exists, get from base"); var baseImage = imagesBase[si.ImageKey]; rebar.LookupParameter(imageParamName).Set(baseImage.imageType.Id); Debug.WriteLine("Set imagetype id" + baseImage.imageType.Id.IntegerValue.ToString() + " to rebar id" + rebar.Id.IntegerValue.ToString()); } else //такая картинка еще не генерировалась - генерируем, добавляем в базу { si.Generate(imagesPrefix); #if R2017 || R2018 || R2019 imType2 = ImageType.Create(doc, si.ScetchImagePath); #elif R2020 imType2 = ImageType.Create(doc, new ImageTypeOptions(si.ScetchImagePath)); #elif R2021 || R2022 ImageTypeOptions ito = new ImageTypeOptions(si.ScetchImagePath, false, ImageTypeSource.Import); imType2 = ImageType.Create(doc, ito); #endif Debug.WriteLine("Create imagetype id=" + imType2.Id.IntegerValue.ToString()); Parameter imageparam = rebar.LookupParameter(imageParamName); if (imageparam == null) { string msg = "Нет параметра " + imageParamName + " в элементе id" + rebar.Id.IntegerValue.ToString(); Debug.WriteLine(msg); System.Windows.Forms.MessageBox.Show(msg); throw new Exception(msg); } if (imageparam.StorageType != StorageType.ElementId) { string msg = "Неверный тип параметра " + imageParamName; Debug.WriteLine(msg); System.Windows.Forms.MessageBox.Show(msg); System.Environment.Exit(1); } imageparam.Set(imType2.Id); si.imageType = imType2; imagesBase.Add(si.ImageKey, si); Debug.WriteLine("Scetch is created, ImageType id=" + imType2.Id.IntegerValue.ToString()); } }
/// <summary> /// Collect the parameters and export /// </summary> /// <returns></returns> public override bool Import() { using (Transaction t = new Transaction(m_activeDoc)) { t.SetName("Import"); t.Start(); // Step 1: Create an ImageType //ImageTypeOptions specifies the source of the image, and how to create the ImageType. // It can be used to specify: // - The image file. Either as a local file path, or as an ExternalResourceRef // - Whether to store the local file path as an absolute path or a relative path. // - Whether to create an Import or a Link image. // In addition, if the source is a PDF file, then ImageTypeOptions can be used to specify: // - which page from the PDF to use // - the resolution (in dots-per-inch) at which to rasterize the PDF // For other image types the page number should be 1 (the default), // and the resolution is only used to determine the size of the image. ImageTypeOptions typeOptions = new ImageTypeOptions(m_importFileFullName, true, ImageTypeSource.Import); ImageType imageType = ImageType.Create(m_activeDoc, typeOptions); // Step 2: Create an ImageInstance, but only if the active view is able to contain images. View view = CommandData.Application.ActiveUIDocument.Document.ActiveView; if (ImageInstance.IsValidView(view)) { // ImagePlacementOptions ImagePlacementOptions placementOptions = new ImagePlacementOptions(); placementOptions.PlacementPoint = Autodesk.Revit.DB.BoxPlacement.TopLeft; placementOptions.Location = new XYZ(1, 1, 1); ImageInstance imageInstance = ImageInstance.Create(m_activeDoc, view, imageType.Id, placementOptions); } t.Commit(); } return(true); }
public virtual ImageInsightResponse GetImageInsights( string query = "", int height = 0, int width = 0, int count = 0, int offset = 0, string languageCode = "", AspectOptions aspect = AspectOptions.All, ColorOptions color = ColorOptions.All, FreshnessOptions freshness = FreshnessOptions.All, ImageContentOptions imageContent = ImageContentOptions.All, ImageTypeOptions imageType = ImageTypeOptions.All, LicenseOptions license = LicenseOptions.All, SizeOptions size = SizeOptions.All, SafeSearchOptions safeSearch = SafeSearchOptions.Off, List <ModulesRequestedOptions> modulesRequested = null, float cab = 0f, float cal = 0f, float car = 0f, float cat = 0f, int ct = 0, string cc = "", string id = "", string imgUrl = "", string insightsToken = "") { try { var result = ImageSearchRepository.GetImageInsights(query, height, width, count, offset, languageCode, aspect, color, freshness, imageContent, imageType, license, size, safeSearch, modulesRequested, cab, cal, car, cat, ct, cc, id, imgUrl, insightsToken); return(result); } catch (Exception ex) { Logger.Error("ImageSearchService.GetImageInsights failed", this, ex); } return(null); }
public virtual ImageInsightResponse GetImageInsights( string query = "", int height = 0, int width = 0, int count = 0, int offset = 0, string languageCode = "", AspectOptions aspect = AspectOptions.All, ColorOptions color = ColorOptions.All, FreshnessOptions freshness = FreshnessOptions.All, ImageContentOptions imageContent = ImageContentOptions.All, ImageTypeOptions imageType = ImageTypeOptions.All, LicenseOptions license = LicenseOptions.All, SizeOptions size = SizeOptions.All, SafeSearchOptions safeSearch = SafeSearchOptions.Off, List <ModulesRequestedOptions> modulesRequested = null, float cab = 0f, float cal = 0f, float car = 0f, float cat = 0f, int ct = 0, string cc = "", string id = "", string imgUrl = "", string insightsToken = "") { return(PolicyService.ExecuteRetryAndCapture400Errors( "ImageSearchService.GetImageInsights", ApiKeys.BingSearchRetryInSeconds, () => { var result = ImageSearchRepository.GetImageInsights(query, height, width, count, offset, languageCode, aspect, color, freshness, imageContent, imageType, license, size, safeSearch, modulesRequested, cab, cal, car, cat, ct, cc, id, imgUrl, insightsToken); return result; }, null)); }
protected virtual string GetImageInsightUrl( string query = "", int height = 0, int width = 0, int count = 0, int offset = 0, string languageCode = "", AspectOptions aspect = AspectOptions.All, ColorOptions color = ColorOptions.All, FreshnessOptions freshness = FreshnessOptions.All, ImageContentOptions imageContent = ImageContentOptions.All, ImageTypeOptions imageType = ImageTypeOptions.All, LicenseOptions license = LicenseOptions.All, SizeOptions size = SizeOptions.All, SafeSearchOptions safeSearch = SafeSearchOptions.Off, List <ModulesRequestedOptions> modulesRequested = null, float cab = 0f, float cal = 0f, float car = 0f, float cat = 0f, int ct = 0, string cc = "", string id = "", string imgUrl = "", string insightsToken = "") { StringBuilder sb = new StringBuilder(); sb.Append($"{imageSearchUrl}?q={query}"); if (height > 0) { sb.Append($"&height={height}"); } if (width > 0) { sb.Append($"&width={width}"); } if (count > 0) { sb.Append($"&count={count}"); } if (offset > 0) { sb.Append($"&offset={offset}"); } if (!string.IsNullOrEmpty(languageCode)) { sb.Append($"&mkt={languageCode}"); } var aspectName = Enum.GetName(typeof(AspectOptions), aspect); if (aspectName != null && !aspectName.Equals("All")) { sb.Append($"&aspect={aspectName}"); } var colorName = Enum.GetName(typeof(ColorOptions), color); if (colorName != null && !colorName.Equals("All")) { sb.Append($"&color={colorName}"); } var freshnessName = Enum.GetName(typeof(FreshnessOptions), freshness); if (freshnessName != null && !freshnessName.Equals("All")) { sb.Append($"&freshness={freshnessName}"); } var imageContentName = Enum.GetName(typeof(ImageContentOptions), imageContent); if (imageContentName != null && !imageContentName.Equals("All")) { sb.Append($"&imageContent={imageContentName}"); } var imageTypeName = Enum.GetName(typeof(ImageTypeOptions), imageType); if (imageTypeName != null && !imageTypeName.Equals("All")) { sb.Append($"&imageType={imageTypeName}"); } var licenseName = Enum.GetName(typeof(LicenseOptions), license); if (licenseName != null && !licenseName.Equals("All")) { sb.Append($"&license={licenseName}"); } var sizeName = Enum.GetName(typeof(SizeOptions), size); if (sizeName != null && !sizeName.Equals("All")) { sb.Append($"&size={sizeName}"); } var safeSearchName = Enum.GetName(typeof(SafeSearchOptions), safeSearch); if (safeSearchName != null && !safeSearchName.Equals("All")) { sb.Append($"&safeSearch={safeSearchName}"); } StringBuilder mod = new StringBuilder(); if (modulesRequested != null) { foreach (var m in modulesRequested) { if (mod.Length > 0) { mod.Append(","); } mod.Append(Enum.GetName(typeof(ModulesRequestedOptions), m)); } sb.Append($"&modulesRequested={mod}"); } if (cab > 0f) { sb.Append($"&cab={cab}"); } if (cal > 0f) { sb.Append($"&cal={cal}"); } if (car > 0f) { sb.Append($"&car={car}"); } if (cat > 0f) { sb.Append($"&cat={cat}"); } if (ct > 0) { sb.Append($"&ct={ct}"); } if (!string.IsNullOrEmpty(cc)) { sb.Append($"&cc={cc}"); } if (!string.IsNullOrEmpty(id)) { sb.Append($"&id={id}"); } if (!string.IsNullOrEmpty(imgUrl)) { sb.Append($"&imgUrl={HttpUtility.UrlEncode(imgUrl)}"); } if (!string.IsNullOrEmpty(insightsToken)) { sb.Append($"&insightsToken={insightsToken}"); } return(sb.ToString()); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Application app = commandData.Application.Application; UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; string filename = "pastedImage" + "_" + DateTime.Now.ToString("yyyy-MM-dd HH.mm") + ".jpeg"; string path = ""; if (doc.IsModelInCloud || doc.IsDetached || doc.PathName == null) { path = Path.Combine(Path.GetTempPath(), filename); } else if(doc.IsWorkshared) { path = Path.Combine(Path.GetDirectoryName(doc.GetWorksharingCentralModelPath().CentralServerPath), "PastedImages", filename); } else { path = Path.Combine(Path.GetDirectoryName(doc.PathName), "PastedImages", filename); } Directory.CreateDirectory(Path.GetDirectoryName(path)); if (Clipboard.ContainsImage()) { Image image = (Image)Clipboard.GetDataObject().GetData(DataFormats.Bitmap); Debug.Print(path); image.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg); } else { message = "No image on clipoboard"; return Result.Failed; } XYZ imageLocation = new XYZ(); try { imageLocation = uidoc.Selection.PickPoint("Pick insertion point (midpoint)"); } catch(Autodesk.Revit.Exceptions.OperationCanceledException) { message = "Command cancelled"; return Result.Cancelled; } using (Transaction t1 = new Transaction(doc, "paste image")) { t1.Start(); ImageTypeOptions opt = new ImageTypeOptions(path, false, ImageTypeSource.Import); ImagePlacementOptions pOpt = new ImagePlacementOptions(); pOpt.Location = imageLocation; pOpt.PlacementPoint = BoxPlacement.Center; ImageType imageType = ImageType.Create(doc, opt); ImageInstance.Create(doc, doc.ActiveView, imageType.Id, pOpt); t1.Commit(); } return Result.Succeeded; }